Displaying a Wide Area Map with cowplot
If you want to be particular about the details of the map, for example, execute the following code.
library(sf)
library(ggplot2)
library(gghighlight)
library(ggrepel)
library(cowplot)
db <- combine_fude(d, b, city = "松山市", old_village = "興居島", community = "^(?!釣島).*")
minimap <- ggplot() +
geom_sf(data = db$lg, aes(fill = fill)) +
geom_sf_text(data = db$lg, aes(label = city_kanji), family = "Hiragino Sans") +
gghighlight(fill == 1) +
geom_sf(data = db$community_union, fill = "black", linewidth = 0) +
theme_void() +
theme(panel.background = element_rect(fill = "aliceblue")) +
scale_fill_manual(values = c("white", "gray"))
mainmap <- ggplot() +
geom_sf(data = db$community, fill = "white") +
geom_sf(data = db$fude, aes(fill = RCOM_NAME)) +
geom_point(data = db$community, aes(x = x, y = y), colour = "gray") +
geom_text_repel(data = db$community,
aes(x = x, y = y, label = RCOM_NAME),
nudge_x = c(-.01, .01, -.01, -.012, .005, -.01, .01, .01),
nudge_y = c(.005, .005, 0, .01, -.005, .01, 0, -.005),
min.segment.length = .01,
segment.color = "gray",
size = 3,
family = "Hiragino Sans") +
theme_void() +
theme(legend.position = "none")
bbox <- sf::st_bbox(db$lg[db$lg$fill == 1, ])
ggdraw(mainmap) +
draw_plot(
{minimap +
geom_rect(aes(xmin = bbox$xmin, xmax = bbox$xmax,
ymin = bbox$ymin, ymax = bbox$ymax),
fill = NA,
colour = "black",
size = .5) +
coord_sf(xlim = bbox[c("xmin", "xmax")],
ylim = bbox[c("ymin", "ymax")],
expand = FALSE) +
theme(legend.position = "none")
},
x = .7,
y = 0,
width = .3,
height = .3)
出典:農林水産省「筆ポリゴンデータ(2022年度公開)」および「農業集落境界データ(2022年度)」を加工して作成。