mikemahoney218/mm218.dev

posts/2023-10-31-map-context/index

Opened this issue · 1 comments

Mike Mahoney - Adding context to maps made with ggplot2

How to set the extent of a map based upon a single layer.

https://www.mm218.dev/posts/2023-10-31-map-context/index.html

You can use a bbox to set the limits within coord_sf:

bbox <- st_bbox(johnston_obs)

ggplot() +
  geom_sf(data = nc) +
  geom_sf(data = johnston_obs, color = "red") +
  coord_sf(
    xlim = c(bbox[["xmin"]], bbox[["xmax"]]),
    ylim = c(bbox[["ymin"]], bbox[["ymax"]]),
  )