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

| 市区町村 | 人口 |
|---|---|
| 佐賀市 | 236372 |
| 唐津市 | 122785 |
| 鳥栖市 | 72902 |
| 伊万里市 | 55238 |
| 武雄市 | 49062 |
| 小城市 | 44259 |
| 神埼市 | 31842 |
| 鹿島市 | 29684 |
| 嬉野市 | 27336 |
| みやき町 | 25278 |
| 白石町 | 23941 |
| 有田町 | 20148 |
| 多久市 | 19749 |
| 基山町 | 17501 |
| 吉野ヶ里町 | 16411 |
| 江北町 | 9583 |
| 上峰町 | 9283 |
| 太良町 | 8779 |
| 大町町 | 6777 |
| 玄海町 | 5902 |