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 = -82, xmax = -80.5, ymin = 35.5, ymax = 36,
loc = "left bottom", scale_factor = 2
)
)
)
# Supply base plot for all subplots
base <- ggplot(nc, aes(fill = AREA)) +
geom_sf() +
scale_fill_viridis_c() +
guides(fill = "none") +
theme_void()
with_inset(base)
# Or supply custom plots in each inset_spec, then call with_inset() without plot
config_insetmap(
bbox = st_bbox(nc),
specs = list(
inset_spec(main = TRUE, plot = base),
inset_spec(
xmin = -82, xmax = -80.5, ymin = 35.5, ymax = 36,
loc = "left bottom", scale_factor = 2,
plot = base # Each spec has its own plot
)
)
)
with_inset() # plot parameter is optional now
Run the code above in your browser using DataLab