Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation_map does not work with coord_sf #3653

Closed
markpayneatwork opened this issue Dec 4, 2019 · 3 comments
Closed

Annotation_map does not work with coord_sf #3653

markpayneatwork opened this issue Dec 4, 2019 · 3 comments

Comments

@markpayneatwork
Copy link
Contributor

When usingcoord_sf() to change the projection of a map, the background layer produced by annotation_map() is not getting reprojected.

First, a plot without changing projection, using the annotation_map layer to give more context to North Carolina

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

ggplot() +
  annotation_map(map_data("state"),fill="antiquewhite",colour="darkgrey")+
  geom_sf(data = nc)

image

However, changing the projection looses the annotation layer, but reprojects the geometry layer

ggplot() +
  annotation_map(map_data("state"),fill="antiquewhite",colour="darkgrey")+
  geom_sf(data = nc)+
  coord_sf(crs = st_crs(3347))

image

It looks to me like the annotation_layer is not being reprojected.

@clauswilke
Copy link
Member

This happens because annotation_map() is old code that predates geom_sf(). Only sf layers are reprojected. While it would be nice to reproject other layers, there are numerous technical hurdles that make me think it's not going to happen anytime soon.

At this point, the best way forward is probably to amend the documentation accordingly.

@thomasp85
Copy link
Member

@clauswilke has this been fixed by #3659?

@clauswilke
Copy link
Member

Yes, correct, just need to set the appropriate default crs. This particular case is actually included in the examples, so I think we're good as is.

library(ggplot2)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

ggplot() +
  annotation_map(map_data("state"),fill="antiquewhite",colour="darkgrey")+
  geom_sf(data = nc) +
  coord_sf(crs = st_crs(3347), default_crs = st_crs(4326))

Created on 2022-05-18 by the reprex package (v2.0.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants