【R】愛媛県の人口別コロプレス図
2020年8月30日
愛媛県の市区町村を人口別に塗りつぶしてみます。境界の描画は「地図で見る統計(統計GIS)」の「38000 愛媛県全域 世界測地系緯度経度・Shapefile」から取得します。
library(ggplot2)
library(ggrepel)
library(sf)
library(tidyverse)
library(kableExtra)
map <- read_sf("shp/h27ka38.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

| 市区町村 | 人口 |
|---|---|
| 松山市 | 514865 |
| 今治市 | 158114 |
| 新居浜市 | 119903 |
| 西条市 | 108174 |
| 四国中央市 | 87413 |
| 宇和島市 | 77465 |
| 大洲市 | 44086 |
| 西予市 | 38919 |
| 伊予市 | 36827 |
| 八幡浜市 | 34951 |
| 東温市 | 34613 |
| 松前町 | 30064 |
| 愛南町 | 21902 |
| 砥部町 | 21239 |
| 内子町 | 16742 |
| 鬼北町 | 10705 |
| 伊方町 | 9626 |
| 久万高原町 | 8447 |
| 上島町 | 7135 |
| 松野町 | 4072 |