library(sf)
library(ggplot2)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
config_insetmap(
bbox = st_bbox(nc),
specs = list(
inset_spec(main = TRUE),
inset_spec(
xmin = -84, xmax = -75, ymin = 33, ymax = 37,
loc = "left bottom", width = 0.3
)
)
)
base <- ggplot(nc, aes(fill = AREA)) +
geom_sf() +
scale_fill_viridis_c() +
guides(fill = "none") +
theme_void()
with_inset(base)
# Save with automatically calculated height
ggsave_inset(paste0(tempdir(), "/inset_map.png"), width = 10)
Run the code above in your browser using DataLab