概要
毎月勤労統計の長期時系列表を使って,就業形態別に総実労働時間数の推移をグラフにする。
コードと実行結果
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.2 ✔ tibble 3.2.1
✔ lubridate 1.9.4 ✔ tidyr 1.3.1
✔ purrr 1.0.4
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# ファイルのダウンロード先ディレクトリ作成
dir.create("files", showWarnings = F)
# 毎月勤労統計調査 長期時系列表 実数・指数累積データ
# 表番号1 実数・指数累積データ 実数
download.file(
"https://www.e-stat.go.jp/stat-search/file-download?statInfId=000032189776&fileKind=1",
destfile = "files/maikin.csv",
method = "curl"
)
maikin <- read.csv(
"files/maikin.csv",
fileEncoding = "shift-jis"
) |>
filter(
`年` >= 1993 &
`月` == "CY" &
substr(`産業分類`, 1, 2) == "TL" & `規模` == "T"
)
w_status <- c("就業形態計", "一般労働者", "パートタイム労働者")
maikin |>
mutate(`総実労働時間` = `総実労働時間` * 12) |>
ggplot(
aes(
x = `年`,
y = `総実労働時間`,
color = as.factor(`就業形態`)
)
) +
geom_line() +
geom_point() +
scale_color_hue(
name = "就業形態",
labels = w_status
)