mikemahoney218 / mm218.dev

Code and assets for my personal website at https://mm218.dev
https://mm218.dev
Other
25 stars 14 forks source link

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

Open utterances-bot opened 8 months ago

utterances-bot commented 8 months ago

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

PaulC91 commented 8 months ago

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"]]),
  )