I am making a map in ggplot2
and am trying to rotate the map slightly. Following
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)
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)
CodePudding user response:
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)