Skip to content

Instantly share code, notes, and snippets.

@igproj-fusion
Last active March 24, 2024 07:50
Show Gist options
  • Save igproj-fusion/c73bc851fac66c74a43e8cf9302f813d to your computer and use it in GitHub Desktop.
Save igproj-fusion/c73bc851fac66c74a43e8cf9302f813d to your computer and use it in GitHub Desktop.
pacman::p_load(
openxlsx,
tidyverse,
sf,
rmapshaper)
URL <- "https://www.soumu.go.jp/main_content/000892857.xlsx"
RATIO <- read.xlsx(URL, colNames = FALSE) |>
slice(-(1:9)) |>
filter(X4 != "男") |>
mutate(value = ifelse(X4 == "計",
as.numeric(X22) +
as.numeric(X23) +
as.numeric(X24) +
as.numeric(X25) +
as.numeric(X26),
as.numeric(X16) +
as.numeric(X17) +
as.numeric(X18))) |>
mutate(value2 = lag(value, 1)) |>
filter(X4 == "女") |>
mutate(ratio = value2 / value * 100) |>
mutate(JCODE = substring(X1, 1, 5)) |>
select(JCODE, ratio)
"%!in%" <- Negate("%in%")
NorthernTerr <- c("01695", "01696", "01697",
"01698", "01699", "01700")
JP_geo <- "https://github.com/igproj-fusion/R-gis/raw/main/ESRI_japan_84.geojson"
JP <- read_sf(JP_geo) |>
filter(JCODE %!in% NorthernTerr) |>
filter(SIKUCHOSON != "所属不明地") |>
left_join(RATIO, by = c("JCODE" = "JCODE"))
JP_outline <- JP |> ms_dissolve()
KANTO <- c("茨城県", "栃木県", "群馬県", "埼玉県",
"千葉県", "東京都", "神奈川県")
Kanto <- JP |>
filter(KEN %in% KANTO)
g <- ggplot()
g <- g + geom_sf(data = JP, aes(fill = ratio))
g <- g + scale_fill_gradient(low = "#ffffcc", high = "#781100")
g <- g + geom_sf(data = JP_outline,
color = "white", fill = "white")
g <- g + geom_sf(data = Kanto, aes(fill = ratio))
g <- g + xlim(c(138.39709, 141))
g <- g + ylim(c(34.5, 37.15506))
g <- g + labs(fill = "介護者比")
g <- g + theme_void()
print(g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment