Created
September 17, 2022 04:58
-
-
Save abikoushi/eff237f5e95123bbf8d23e38a8000621 to your computer and use it in GitHub Desktop.
estat api のデモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(estatapi) | |
library(ggplot2) | |
library(dplyr) | |
myappId <-"ここには自分のアプリケーションIDを入れる" | |
#dat_meta <- estat_getStatsList(myappId, "人口動態調査") | |
#View(dat_meta) | |
dat2 <- estat_getStatsData(appId = myappId, statsDataId = "0003411659") | |
jisatsu <-dplyr::filter(dat2, 表章項目=="死亡率", 死因年次推移分類=="Hi16_自殺", 性別!="総数") %>% | |
mutate(year=as.integer(gsub("年","",`時間軸(年次)`))) %>% | |
mutate(age=factor(`年齢(5歳階級)`,levels=c("0~4歳","5~9歳","10~14歳","15~19歳", | |
"20~24歳","25~29歳","30~34歳","35~39歳", | |
"40~44歳","45~49歳","50~54歳","55~59歳", | |
"60~64歳","65~69歳","70~74歳","75~79歳", | |
"80~84歳","85~89歳" ,"90~94歳","95~99歳","100歳以上","不詳"), | |
ordered = TRUE)) %>% | |
dplyr::filter(!is.na(age), !is.na(value), year>=2000) %>% | |
mutate(year=factor(year,ordered = TRUE)) | |
# ggplot(jisatsu, aes(x= `時間軸(年次)` , fill = value, y = age))+ | |
# geom_tile()+ | |
# facet_grid(~性別, scales = "free")+ | |
# scale_fill_viridis_c()+ | |
# theme_classic(14,"Osaka")+ | |
# theme(axis.text = element_text(colour="black"), | |
# axis.text.x = element_text(angle = 270, hjust=0), | |
# strip.background = element_blank())+ | |
# labs(fill="人口10万対", x="",y="年齢") | |
ggplot(jisatsu, aes(x= age, y=value,fill=性別))+ | |
geom_col(width = 1)+ | |
scale_y_continuous(n.breaks = 3)+ | |
facet_grid(`時間軸(年次)`~., scales = "free_y")+ | |
scale_fill_manual(values = c("orange", "royalblue"))+ | |
theme_classic(14,"Osaka")+ | |
theme(axis.text = element_text(colour="black"), | |
axis.text.x = element_text(angle = 270, hjust=0), | |
strip.text.y = element_text(angle = 0, hjust=0), | |
strip.background = element_blank())+ | |
labs(y="人口10万対", x="年齢(5歳階級)")+ | |
ggtitle("人口動態調査 人口動態統計 確定数 死亡(死因年次推移分類:自殺)") | |
ggsave("./Desktop/suicide.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment