# 準備 ----------------------------------------------------------------------
##パッケージの読みこみ
library(pacman)
pacman::p_load(tidyverse,ggplot2,sf)
##データの準備
df_23<-read.csv("hoikujo_2023.csv")
###保育所充足率についての列を作成
df_23<-df_23 %>% mutate(jusokuritsu=riyoujidou/riyouteiin)
###データの確認
head(df_23)
###サイズの確認
dim(df_23)
# 地図データの準備 ----------------------------------------------------------------
library(sf)
states01 <- sf::read_sf("ne_10m_admin_1_states_provinces.shp")
###日本のデータのみを抽出
japan01 <- states01 %>%
dplyr::filter(adm0_a3 == 'JPN')
japan01
iso_pref<-read.csv("iso_code.csv")
iso_pref
df_23_joined <- df_23 |>
inner_join(iso_pref,by="todoufuken")
df_23_joined
japan02<-japan01%>%
inner_join(df_23_joined,by="iso_3166_2")
japan02
# 描写 ----------------------------------------------------------------------
japan02 <- japan02 %>%
mutate(jusokuritsu_cat = cut(jusokuritsu,
breaks = c(-Inf, 0.85, 0.9, 0.95, 1.00, Inf),
labels = c("85%未満", "85~90%", "90~95%", "95~100%", "100%以上")))
# 色の設定
color_palette <- colorRampPalette(c("Blue","White", "Red"))
colors <- color_palette(5) # 5段階の色を生成
# ggplot2 を使用して地図を描画
ggplot(data = japan02) +
geom_sf(aes(fill = jusokuritsu_cat)) +
scale_fill_manual(values = colors) +
theme_void() +
labs(fill = "値の範囲", title = "2023年度における保育所定員充足率") +
theme(plot.title = element_text(hjust = 0.5), text = element_text(size = 20))
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme