2

I am making a map in ggplot2 and am trying to rotate the map slightly. Following previous stackoverflow questions, I adjusted the CRS to an oblique mercator projection. That works great.

However, I'm using the ggsn package to include a north arrow, and either the north arrow totally disappears, or is rotated along with the new CRS projection.

How can I rotate a map made with ggplot2 and include a north arrow that actually points north?

Here's a reproducible example:

library(sf)
library(ggplot2)
library(tigris)
library(ggsn)

places<-places(state = 42)
places<-places[places$NAME=="Philadelphia",]
roads<-roads(state = "42",county = "101")

ggplot()+
  geom_sf(data = places,fill=NA,color='black',linewidth = 1)+
  geom_sf(data = roads[roads$RTTYP=="S",],color="black",linewidth=1)+
  north(data = places,
        location = 'topleft',
        scale = .1,
        symbol = 11)+
  coord_sf(datum = NA)

This gives: enter image description here

Changing the CRS to the oblique mercator yields a rotated image but no north arrow:

crs_string = "+proj=omerc +lat_0=39.95276 +lonc=-75.16340, +alpha=0 +k_0=1 +datum=WGS84 +units=m +no_defs +gamma=-11"

ggplot()+
  geom_sf(data = places,fill=NA,color='black',linewidth = 1)+
  geom_sf(data = roads[roads$RTTYP=="S",],color="black",linewidth=1)+
  north(data = places,
        location = 'topleft',
        scale = .1,
        symbol = 11)+
  coord_sf(datum = NA, crs = crs_string)

enter image description here

Finally, changing the data projection for the north arrow brings the north arrow back, but yields a north arrow that points directly "up" rather than to true north.

ggplot()+
  geom_sf(data = places,fill=NA,color='black',linewidth = 1)+
  geom_sf(data = roads[roads$RTTYP=="S",],color="black",linewidth=1)+
  north(data = st_transform(places,crs = "+proj=omerc +lat_0=39.95276 +lonc=-75.16340, +alpha=10 +k_0=1 +datum=WGS84 +units=m +no_defs +gamma=0"),
        location = 'topleft',
        scale = .1,
        symbol = 11)+
  coord_sf(datum = NA, crs = crs_string)

enter image description here

thebenjaminp
  • 102
  • 5

1 Answers1

0

Okay, not with ggsn but with ggspatial I was able to get this to work:

library(sf)
library(ggplot2)
library(tigris)
library(ggspatial)

places<-places(state = 42)
places<-places[places$NAME=="Philadelphia",]
roads<-roads(state = "42",county = "101")

crs_string = "+proj=omerc +lat_0=39.95276 +lonc=-75.16340, +alpha=0 +k_0=1 +datum=WGS84 +units=m +no_defs +gamma=-11"

ggplot()+
  geom_sf(data = places,fill=NA,color='black',linewidth = 1)+
  geom_sf(data = roads[roads$RTTYP=="S",],color="black",linewidth=1)+
  annotation_north_arrow(which_north = "true",style = north_arrow_minimal(),location ="tl")+
  coord_sf(datum = NA, crs = crs_string)

enter image description here

thebenjaminp
  • 102
  • 5