nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
base <- ggplot() +
geom_sf(data = nc, fill = "grey90") +
theme_minimal()
# Example 1: Grid north (no CRS required), bottom-left
base + annotation_compass()
# Example 2: Custom style & position (top-left)
base + annotation_compass(location = "tl", style = compass_sinan())
# Example 3: True north (requires a CRS)
base +
coord_sf(crs = "+proj=lcc +lon_0=-100 +lat_1=33 +lat_2=45") +
annotation_compass(location = "br", which_north = "true")
Run the code above in your browser using DataLab