【R】広島県の人口別コロプレス図
2020年8月26日
広島県の市区町村を人口別に塗りつぶしてみます。境界の描画は「地図で見る統計(統計GIS)」の「34000 広島県全域 世界測地系緯度経度・Shapefile」から取得します。
library(ggplot2)
library(ggrepel)
library(sf)
library(tidyverse)
library(kableExtra)
map <- read_sf("shp/h27ka34.shp") # 広島県のシェープファイル
dat <- map %>%
group_by(CITY_NAME) %>% # 市名でグルーピング
summarize('Pop.total' = sum(JINKO)) %>% # グループ単位で領域結合, 人口計算
mutate( # 重心計算と座標値の抽出
centroid = st_centroid(geometry),
x = st_coordinates(centroid)[, 1],
y = st_coordinates(centroid)[, 2]
) %>%
arrange(desc(Pop.total))
dat %>%
ggplot() +
geom_sf(aes(fill = Pop.total)) + # 人口毎に色分け
coord_sf(datum = NA) +
scale_fill_viridis_c(alpha = 0.6) +
theme_void()+
geom_text_repel(aes(x = x, y = y, label = CITY_NAME), col="black",
family = "JP4", size = 3)
table_df<-data.frame(市区町村=dat$CITY_NAME, 人口=dat$Pop.total)
library(clipr)
table_df %>%
kable(align = "c", row.names=FALSE) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T) %>%
collapse_rows(columns = 1, valign = "middle") %>%
write_clip

| 市区町村 | 人口 |
|---|---|
| 福山市 | 464811 |
| 安佐南区 | 242512 |
| 呉市 | 228552 |
| 東広島市 | 192907 |
| 西区 | 190929 |
| 安佐北区 | 145018 |
| 南区 | 142728 |
| 尾道市 | 138626 |
| 佐伯区 | 136699 |
| 中区 | 136640 |
| 東区 | 120155 |
| 廿日市市 | 114906 |
| 三原市 | 96194 |
| 安芸区 | 79353 |
| 三次市 | 53615 |
| 府中町 | 51053 |
| 府中市 | 40069 |
| 庄原市 | 37000 |
| 安芸高田市 | 29488 |
| 海田町 | 28667 |
| 大竹市 | 27865 |
| 竹原市 | 26426 |
| 江田島市 | 24339 |
| 熊野町 | 23755 |
| 北広島町 | 18918 |
| 世羅町 | 16337 |
| 坂町 | 12747 |
| 神石高原町 | 9217 |
| 大崎上島町 | 7992 |
| 安芸太田町 | 6472 |