My map points landed in the ocean
We put three New York places on a map and they show up near Antarctica, or in the middle of Asia. The data is right; the map just got the numbers in the wrong places. Here are the three usual reasons and a quick check that catches them all.
What we need
- R 4.1 or newer
- ggplot2 and maps
- A few places with latitude and longitude (we make them below)
Three places in New York
Latitude says how far north (New York is about 40.7). Longitude says how far east or west; west of London it is negative (New York is about -74).
library(ggplot2)
places <- data.frame(
name = c("Central Park", "Coney Island", "Yankee Stadium"),
lat = c(40.7829, 40.5755, 40.8296),
lon = c(-73.9654, -73.9707, -73.9262)
)
world <- map_data("world")Loading the checked output…
Mix-up 1: latitude and longitude swapped
On a map, x goes left and right (longitude) and y goes up and down (latitude). Swap them and New York lands far south, in the ocean near Antarctica.
ggplot() +
geom_polygon(data = world, aes(long, lat, group = group), fill = "grey85") +
geom_point(data = places, aes(x = lat, y = lon), color = "red", size = 3) +
coord_quickmap()Loading the checked output…

Mix-up 2: the minus sign went missing
Some files drop the minus sign, or write 73.97 W. Without the minus, the points jump to Asia.
ggplot() +
geom_polygon(data = world, aes(long, lat, group = group), fill = "grey85") +
geom_point(data = places, aes(x = abs(lon), y = lat), color = "red", size = 3) +
coord_quickmap()Loading the checked output…

The right way
x = longitude, y = latitude, minus sign kept. Zoom in on the New York area to see the points.
ggplot() +
geom_polygon(data = map_data("state"), aes(long, lat, group = group), fill = "grey85", color = "white") +
geom_point(data = places, aes(x = lon, y = lat), color = "red", size = 3) +
coord_quickmap(xlim = c(-75, -72.5), ylim = c(40, 41.5))Loading the checked output…

Taste test: a box check
Before we draw, check that every point sits in a box around the place we expect. For New York City: latitude 40.4 to 41, longitude -74.3 to -73.6.
in_nyc <- with(places, lat > 40.4 & lat < 41 & lon > -74.3 & lon < -73.6)
stopifnot(all(in_nyc))
all(in_nyc)Loading the checked output…
Mix-up 3: with the sf package, longitude goes first
When we turn a table into map points with the sf package, list longitude first, then latitude, and say the numbers are plain latitude and longitude (code 4326).
library(sf)
pts <- st_as_sf(places, coords = c("lon", "lat"), crs = 4326)Kitchen tip: the habit that prevents this
Say it out loud: x is longitude, y is latitude. Then run a box check with the area we expect before we draw any map.
Three common mix-ups
- Latitude and longitude columns swapped in the file itself, not just in the chart.
- Coordinates stored as text with a degree sign, like "40.78°", which turn into NA.
- Mixing map shapes in one coordinate system with points in another (in sf, use st_transform() to match them).
Quick check
A point that should be in New York shows up in western China. What went wrong?
Practice: try it here
One of these four New York places has its latitude and longitude swapped. Make bad hold the name of every place that falls outside the New York City box.
Change the code in the box, then press Run to see what it does, and Check my answer when it looks right. It all runs in this browser, so nothing is sent anywhere.
New York City sits between latitude 40.4 and 41, and longitude -74.3 and -73.6. Keep the names where that test is FALSE.
places <- data.frame(
name = c("Central Park", "Brooklyn Bridge", "Flushing Meadows", "Staten Island Ferry"),
lat = c(40.7829, -73.9969, 40.7400, 40.6437),
lon = c(-73.9654, 40.7061, -73.8408, -74.0736)
)
in_nyc <- with(places, lat > 40.4 & lat < 41 & lon > -74.3 & lon < -73.6)
bad <- places$name[!in_nyc]
bad- x = longitude, y = latitude
- west and south are negative
- sf: coords = c("lon", "lat")
- box check before drawing
Keep the recipe card
A one-picture summary to pin next to a screen or send to a friend who is stuck on the same thing.
Trying this on other data? Check the row counts and results before and after each step. Package versions change, so if something here works differently, please tell us. Every output on this page comes from running the code above in R; please cross-check before relying on it for our work.