ライブラリ
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── 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
library(magrittr)
##
## Attaching package: 'magrittr'
##
## The following object is masked from 'package:purrr':
##
## set_names
##
## The following object is masked from 'package:tidyr':
##
## extract
データ読み込み
PY <- read_csv("/Users/myang/Desktop/23A/社会調査/社会調査/data/PY110.csv")
## Rows: 3367 Columns: 5377
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (5377): PanelID, BLOCK, SIZE, sex, ybirth, mbirth, ZQ02A, zq02ay48, zq02...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
PM <- read_csv("/Users/myang/Desktop/23A/社会調査/社会調査/data/PM110.csv")
## Rows: 1433 Columns: 5377
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (5377): PanelID, BLOCK, SIZE, sex, ybirth, mbirth, ZQ02A, zq02ay48, zq02...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
JLPS <- rbind(PY,PM)
「男性の仕事は収入を得ること、女性の仕事や家庭と家族の面倒をみることだ」という意識について、性別ごとの時系列を可視化してください。
JLPS %>%
select(c("PanelID",
"sex",
"ZQ39A",
"BQ32A",
"DQ28A",
"FQ30A",
"HQ31A",
"JQ30A",
)) -> gender_role_awareness
gender_role_awareness %>%
pivot_longer(col = -c("PanelID","sex"),names_to = "year", values_to = "gender_role_awareness") -> gender_role_awareness_long
gender_role_awareness_long %<>%
mutate(year = case_when(str_detect(year,"ZQ") ~ 2006,
str_detect(year,"AQ") ~ 2007,
str_detect(year,"BQ") ~ 2008,
str_detect(year,"CQ") ~ 2009,
str_detect(year,"DQ") ~ 2010,
str_detect(year,"EQ") ~ 2011,
str_detect(year,"FQ") ~ 2012,
str_detect(year,"HQ") ~ 2013,
str_detect(year,"IQ") ~ 2014,
str_detect(year,"JQ") ~ 2015
)
)
gender_role_awareness_long %>%
mutate(gender = factor(sex,
levels = 1:2,
labels = c("male","female")
)
) %>%
group_by(gender,year) %>%
summarize(gender_role_awareness_mean = mean(gender_role_awareness, na.rm = TRUE)) %>%
ggplot(aes(x=year, y= gender_role_awareness_mean, color = gender)) +
geom_line() +
geom_point() +
scale_x_continuous(breaks = 2005:2016) +
theme_bw()
## `summarise()` has grouped output by 'gender'. You can override using the
## `.groups` argument.
その他質問や感想などあれば記入してください。 質問ですが、今自分のgender_role_awarenessの項目は高ければ高いほど「男性の仕事は収入を得ること、女性の仕事や家庭と家族の面倒をみることだ」に賛同していないようになっているのですが、それを逆にしたいです。pivot_longer()を用いて図において1ー5の項目を反転したい時はどうすればいいですか?それとも事前にデータをmutateした方が良いでしょうか?