Created
October 24, 2022 09:31
-
-
Save abikoushi/3956e0e32c03bf5a70c372481823c4a8 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) | |
| library(tidyr) | |
| myappId <-"ここには自分のアプリケーションIDを入れる" | |
| # データを探す | |
| # dat_meta <- estat_getStatsList(myappId, "労働力調査") | |
| # View(dat2) | |
| dat1 <- estat_getStatsData(appId = myappId, statsDataId = "0003005798") | |
| datcol <- dplyr::filter(dat1, (cat02_code=="00"|cat02_code=="02"|cat02_code=="08") & cat03_code =="0" & area_code =="00000") %>% | |
| mutate(yearMonth = as.Date(paste(sub("月","",sub("年","-",`時間軸(月次)`)),"01",sep="-"))) %>% | |
| dplyr::select(yearMonth, value,`就業状態`) %>% | |
| spread(`就業状態`,value) %>% | |
| mutate(y1 =`完全失業者`/`15歳以上人口`, y2=`就業者`/`15歳以上人口`) %>% | |
| pivot_longer(y1:y2) %>% | |
| mutate(name=ifelse(name=="y1","完全失業者/15歳以上人口","就業者/15歳以上人口")) | |
| ggplot(datcol, aes(x=yearMonth,y=value))+ | |
| stat_summary_bin(geom = "line", fun = mean,fun.args = list(na.rm=FALSE), nbins=nrow(datcol)/24, colour="royalblue")+ | |
| geom_point(alpha=0.5)+ | |
| scale_x_date(date_breaks = "3 year", date_labels = "%Y")+ | |
| facet_wrap(~name, scales = "free_y", nrow=2, strip.position = "right")+ | |
| labs(x="年", y="")+ | |
| theme_classic(14,"Osaka")+ | |
| theme(legend.position = "bottom") | |
| ggsave("./Desktop/koyo.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment