Setting boundaries in ggplot2
I was trying to figure out how to set the boundaries of maps created in ggplot2 to focus on a region of the state or a few counties. It’s actually not that hard to do in ggplot2 and R.
Basically you create a bounding box based on a shape like a few counties.
county <- counties(state=’ny’, cb=TRUE)
bbox <- county %>% filter(NAME %in% c(‘Oswego’,’Madison’)) %>% st_bbox()
Then add this line to the ggplot statement to set the boundaries of the plot. Simple enough.
coord_sf(xlim=c(bbox[1], bbox[3]), ylim=c(bbox[2], bbox[4])) +