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

| 市区町村 | 人口 |
|---|---|
| 大分市 | 478146 |
| 別府市 | 122138 |
| 中津市 | 83965 |
| 佐伯市 | 72211 |
| 日田市 | 66523 |
| 宇佐市 | 56258 |
| 臼杵市 | 38748 |
| 豊後大野市 | 36584 |
| 由布市 | 34262 |
| 杵築市 | 30185 |
| 国東市 | 28647 |
| 日出町 | 28058 |
| 豊後高田市 | 22853 |
| 竹田市 | 22332 |
| 津久見市 | 17969 |
| 玖珠町 | 15823 |
| 九重町 | 9645 |
| 姫島村 | 1991 |