Reputation: 47
I'm using ggplot2 to plot a projected polygon (sf) object. When I use it, ggplot is ploting the axis as degrees (north/south - east/west), however I prefer that it keeps the axis as northing-easting (which is the correct).
Here is an example:
library(rnaturalearth)
library(ggplot2)
library(sf)
# Get world polygons
world <- ne_countries()
# Reproject to equal area lambers projection
proj <- "+proj=laea +lat_0=0 +lon_0=-70 +x_0=0 +y_0=0 +datum=WGS84 +units=km +no_defs"
world_proj <- spTransform(world, CRS(proj))
# Convert to sf
world_proj <- st_as_sf(world_proj)
# Plot it --- showing correctly as easting-northing
plot(world_proj, axes = T, max.plot = 1,
xlim = c(-3200, 4500), ylim = c(-4900, 4900))
# Plot with ggplot - converting to degrees north/south - west/east
# I need it in north easting!
ggplot()+
geom_sf(data = world_proj)+
coord_sf(xlim = c(-3200, 4500), ylim = c(-4900, 4900))
I tried to change arguments on coord_sf, but it doesn't helped. I appreciate any advice you can give!
Upvotes: 1
Views: 401
Reputation: 94202
Change the datum
argument:
ggplot()+
geom_sf(data = world_proj)+
coord_sf(xlim = c(-3200, 4500), ylim = c(-4900, 4900),
datum=st_crs(world_proj))
Documentation:
datum: CRS that provides datum to use when generating graticules.
Upvotes: 3