Skip to content

Instantly share code, notes, and snippets.

@igproj-fusion
Created March 26, 2024 09:04
Show Gist options
  • Save igproj-fusion/a84e69ccb8f40a0c56b106006286b898 to your computer and use it in GitHub Desktop.
Save igproj-fusion/a84e69ccb8f40a0c56b106006286b898 to your computer and use it in GitHub Desktop.
pacman::p_load(
sf,
estatapi,
tidyverse)
appId <- "*************************************"
res <- estat_getStatsData(
appId = appId,
statsDataId = "0000020201"
)
Name <- colnames(res)
Name[4] <- "A人口世帯"
colnames(res) <- Name
Chiba <- res |>
filter(調査年 == "2020年度") |>
filter(substring(area_code, 1, 2) == "12") |>
filter(A人口世帯 %in% c("A1405_0~5歳人口",
"A1303_65歳以上人口",
"A6101_従業も通学もしていない人口")) |>
select(code = area_code, type = A人口世帯, value) |>
mutate(value2 = lag(value, 60)) |>
mutate(value3 = lag(value2, 60)) |>
slice(-c(1:120)) |>
mutate(u5o65 = value2 + value3) |>
mutate(ratio = value / u5o65) |>
select(code, 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"
CHIBA <- read_sf(JP_geo) |>
filter(JCODE %!in% NorthernTerr) |>
filter(SIKUCHOSON != "所属不明地") |>
filter(KEN == "千葉県") |>
left_join(Chiba, by = c("JCODE" = "code"))
g <- ggplot()
g <- g + geom_sf(data = CHIBA, aes(fill = ratio))
g <- g + scale_fill_gradient(low = "#ffffcc", high = "#581100")
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