你可以考虑{cowplot};它最适合 ggplots。
例如,考虑以下代码:
library(tigris)
roads_orlando <- roads(state = "FL",
county = c("Orange")) # Orlando does not seem to be a legit county name :(
roads_miami <- roads(state = "FL",
county = c("Miami-Dade"))
# Miami is bigger of the two; we need to enlarge Orlando a bit
bbox_miami <- st_bbox(roads_miami) # bouding box of Miami
width_miami <- bbox_miami[3] - bbox_miami[1]
height_miami <- bbox_miami[4] - bbox_miami[2]
# centroid of Orlando; to this we will add the extent of Miami
orlando_centroid <- st_centroid(st_bbox(roads_orlando) %>%
st_as_sfc())
library(ggplot2)
gg_or <- ggplot(data = roads_orlando) +
geom_sf() +
coord_sf(xlim = c(st_coordinates(orlando_centroid)[1] - width_miami / 2,
st_coordinates(orlando_centroid)[1] + width_miami / 2),
ylim = c(st_coordinates(orlando_centroid)[2] - height_miami / 2,
st_coordinates(orlando_centroid)[2] + height_miami / 2))
gg_md <- ggplot(data = roads_miami) +
geom_sf()
cowplot::plot_grid(gg_or, gg_md)