【R】秋田県の人口別コロプレス図
2020年8月12日
秋田県の市区町村を人口別に塗りつぶしてみます。境界の描画は「地図で見る統計(統計GIS)」の「05000 秋田県全域 世界測地系緯度経度・Shapefile」から取得します。
library(ggplot2)
library(ggrepel)
library(sf)
library(tidyverse)
library(kableExtra)
library(ggspatial)
map <- read_sf("shp/h27ka05.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() +
annotation_map_tile(zoomin = 0) +
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) +
labs(caption = "\U00a9 OpenStreetMap contributors") +
theme_minimal()
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

| 市区町村 | 人口 |
|---|---|
| 秋田市 | 315814 |
| 横手市 | 92197 |
| 大仙市 | 82783 |
| 由利本荘市 | 79927 |
| 大館市 | 74175 |
| 能代市 | 54730 |
| 湯沢市 | 46613 |
| 北秋田市 | 33224 |
| 潟上市 | 33083 |
| 鹿角市 | 32038 |
| 男鹿市 | 28375 |
| 仙北市 | 27523 |
| にかほ市 | 25324 |
| 美郷町 | 20279 |
| 三種町 | 17078 |
| 羽後町 | 15319 |
| 五城目町 | 9463 |
| 八峰町 | 7309 |
| 八郎潟町 | 6080 |
| 小坂町 | 5339 |
| 井川町 | 4986 |
| 藤里町 | 3359 |
| 大潟村 | 3110 |
| 東成瀬村 | 2610 |
| 上小阿仁村 | 2381 |