4

I am having problems aligning two maps. They appear to have the same crs but still look off a bit. Notice the California-Nevada border and the California coast. Below is the code I am using:

enter image description here

library(ggmap)
 library(sf)
 library(USAboundaries)

state_names <- c("california") 
CA_counties <- us_counties(resolution="high",states=state_names)
CAbox <- c(bottom = 32.213, top = 42.163 , right = -113.95, left = -124.585)
camap2 <- get_stamenmap(bbox = CAbox, zoom = 6, maptype = "terrain")
ggmap(camap2)

ggmap(camap2) + geom_sf(data=CA_counties,color='red',inherit.aes = FALSE,alpha=0.2) +
 theme_void()

Could someone guide me in the right direction? Thanks

Salvador
  • 1,229
  • 1
  • 11
  • 19
  • 1
    Might want to look at [this previous answer](https://stackoverflow.com/a/50844502/7547327). ggmap & geom_sf seem to use crs 3857 & 4326 respectively. They're usually close, but not exact. – mrhellmann May 12 '22 at 13:06
  • 1
    And the same answer (& author) with more discussion in an open github issue: https://github.com/dkahle/ggmap/issues/160 – mrhellmann May 12 '22 at 13:34
  • @--mrhellmann, thanks. It works now. I adapted my fs object to the example here: https://stackoverflow.com/questions/47749078/how-to-put-a-geom-sf-produced-map-on-top-of-a-ggmap-produced-raster/50844502#50844502 – Salvador May 13 '22 at 02:06

0 Answers0