I'm trying to plot some points on a Mollweide projected map, but adding coord_sf to my ggplot code causes all of the points to be plotted at 0,0. Here is some code where I grab the country data, project it to Mollweide (crs=54009), then load my points data. Note that the points data has already been projected to Mollweide, so it should need no reprojection. If I plot the data without using coord_sf, the points show up as they should, but of course the projection looks wrong. But if I add coord_sf, it seems to collapse all of the points to 0,0.
library(ggplot2)
library(rnaturalearth)
library(rnaturalearthdata)
library(sf)
#country data
countries <- ne_countries(returnclass = "sf")
world_proj <- st_transform(countries, crs = 54009)
#points, already projected to same crs
points <- data.frame(
land = c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,
FALSE),
x = c(-66.89695, 143.28066, 51.63533, -76.16409, 177.77862,
171.00648, 101.41291, -147.60461, 117.14617, 107.37859),
y = c(76.77662, -47.098278, -30.987178, 84.906883, -70.977776,
-7.352523, -78.711968, 23.036947, -51.915945, -3.458423)
)
#doesnt work
ggplot() +
geom_sf(data = countries, fill = "grey80", col = "grey40", lwd = 0.3) +
geom_point(data = points, aes(x, y, color = land)) +
theme_minimal() +
coord_sf(crs = 54009) +
theme(axis.text = element_blank())
#works for the points, but the projection is wrong now
ggplot() +
geom_sf(data = countries, fill = "grey80", col = "grey40", lwd = 0.3) +
geom_point(data = points, aes(x, y, color = land)) +
theme_minimal() +
#coord_sf(crs = 54009) +
theme(axis.text = element_blank())