plotting a sf object with geom_sf() with any projection other than lat-long

Viewed 5280

I am trying to plot a polygon with geom_sf() in any projection other than lat-long.

I am using the example found in the manual pages for geom_sf() Importing the dataset:

nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

transforming from latlong into epsg:3857

nc_3857 <- sf::st_transform(nc, "+init=epsg:3857")

Finally plot with ggplot2 defining the crs of the plot:

ggplot() +
 geom_sf(data = nc_3857, colour = "red", fill = NA) +
 coord_sf(crs=st_crs(3857))

I keep getting a map in wgs84 (i.e. epsg:4326) with lat-long axes. I want to have the axes in meters, so I need ggplot to plot the projected polygon. What am I doing wrong?

2 Answers
Related