Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created June 25, 2024 23:58
Show Gist options
  • Save ryanburge/8d8f17765b8160c291bd7d067d6c193b to your computer and use it in GitHub Desktop.
Save ryanburge/8d8f17765b8160c291bd7d067d6c193b to your computer and use it in GitHub Desktop.
gg1 <- gss %>%
filter(year <= 2018) %>%
mutate(work = fefam) %>%
mutate(work = frcode(work == 4 ~ "Strongly Disagree",
work == 3 ~ "Disagree",
work == 2 ~ "Agree",
work == 1 ~ "Strongly Agree")) %>%
group_by(year) %>%
ct(work, wt= wtssall, show_na = FALSE)
gg2 <- gss %>%
filter(year >= 2020) %>%
mutate(work = fefam) %>%
mutate(work = frcode(work == 4 ~ "Strongly Disagree",
work == 3 ~ "Disagree",
work == 2 ~ "Agree",
work == 1 ~ "Strongly Agree")) %>%
group_by(year) %>%
ct(work, wt= wtssnrps, show_na = FALSE)
gg <- bind_rows(gg1, gg2)
gg %>%
ggplot(., aes(x = year, y = pct, color = work, group = work)) +
geom_point(stroke = 1, shape = 21, alpha = .45) +
geom_labelsmooth(aes(label = work), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size = 6, linewidth = 1, boxlinewidth = 0.3, hjust = .75) +
scale_y_continuous(labels = percent, limits = c(0, .50)) +
theme_rb() +
scale_color_manual(values = c("#28666e", "#5f2680", "#B5B682", "azure4", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680")) +
theme(strip.text = element_text(size = 25)) +
labs(x = "", y = "Share Agreeing", title = "It is much better for everyone involved if the man is the achiever outside the home\nand the woman takes care of the home and family",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 1977-2022") +
add_text(x = 1977, y = .038, word = "6%", sz = 7) +
add_text(x = 1977, y = .21, word = "19%", sz = 7) +
add_text(x = 1977, y = .257, word = "28%", sz = 7) +
add_text(x = 1977, y = .49, word = "47%", sz = 7) +
add_text(x = 2022, y = .46, word = "44%", sz = 7) +
add_text(x = 2022, y = .36, word = "31%", sz = 7) +
add_text(x = 2022, y = .155, word = "19%", sz = 7) +
add_text(x = 2022, y = .075, word = "6%", sz = 7)
save("gss_women_work.png")
gg1 <- gss %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
filter(year <= 2018) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(year, pid3) %>%
socsci::mean_ci(work, wt= wtssall, ci = .84)
gg2 <- gss %>%
filter(year >= 2020) %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(year, pid3) %>%
socsci::mean_ci(work, wt= wtssnrps, ci = .84)
gg <- bind_rows(gg1, gg2)
gg %>%
filter(year >= 1977) %>%
ggplot(., aes(x = year, y = mean, color = pid3, group = pid3)) +
geom_point(stroke = 1, shape = 21, alpha = .45) +
geom_labelsmooth(aes(label =pid3), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size = 6, linewidth = 1, boxlinewidth = 0.3, hjust = .75) +
scale_y_continuous(labels = percent, limits = c(0, .70)) +
theme_rb() +
pid3_color() +
theme(strip.text = element_text(size = 25)) +
labs(x = "", y = "Share Agreeing", title = "It is much better for everyone involved if the man is the achiever outside the home\nand the woman takes care of the home and family",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 1977-2022")
save("gss_women_work_pid3.png")
gg1 <- gss %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
filter(year <= 2018) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(year, pid3, gender) %>%
socsci::mean_ci(work, wt= wtssall, ci = .84)
gg2 <- gss %>%
filter(year >= 2020) %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(year, pid3, gender) %>%
socsci::mean_ci(work, wt= wtssnrps, ci = .84)
gg <- bind_rows(gg1, gg2) %>% filter(gender != "NA")
gg %>%
filter(year >= 1977) %>%
filter(pid3 == "Democrat" | pid3 == "Republican") %>%
ggplot(., aes(x = year, y = mean, color = pid3, group = pid3)) +
geom_point(stroke = 1, shape = 21, alpha = .45) +
geom_labelsmooth(aes(label =pid3), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size = 6, linewidth = 1, boxlinewidth = 0.3, hjust = .75) +
scale_y_continuous(labels = percent, limits = c(0, .72)) +
theme_rb() +
scale_color_manual(values = c("dodgerblue3", "firebrick3")) +
facet_wrap(~ gender) +
theme(strip.text = element_text(size = 25)) +
labs(x = "", y = "Share Agreeing", title = "It is much better for everyone involved if the man is the achiever outside the home\nand the woman takes care of the home and family",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 1977-2022")
save("gss_women_work_pid3_gender.png")
all <- gss %>%
filter(year >= 2020) %>%
gss_reltrad6(reltrad) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(reltrad) %>%
socsci::mean_ci(work, wt= wtssnrps, ci = .84) %>% filter(reltrad != "NA")
# all <- gss %>%
# filter(year >= 2020) %>%
# mutate(work = fefam) %>%
# mutate(work = case_when(work == 1 | work == 2 ~ 1,
# work == 3 | work == 4 ~ 0)) %>%
# mean_ci(work, wt= wtssnrps, ci = .84)
all %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(reltrad, mean), y = mean, fill = reltrad)) +
geom_col(color = "black") +
coord_flip() +
y_pct() +
theme_rb() +
error_bar() +
lab_bar(top = FALSE, type = lab, pos = .03, sz = 12) +
geom_text(aes(y = .03, label = ifelse(reltrad == "Black Prot.", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font", color = "white") +
geom_text(aes(y = .03, label = ifelse(reltrad == "No Religion", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font", color = "white") +
geom_text(aes(y = .03, label = ifelse(reltrad == "Mainline", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font", color = "white") +
scale_fill_manual(values = c("#e1e1e1","#28666e", "#5f2680", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680")) +
labs(x = "", y = "Share Agreeing", title = "It is much better for everyone involved if the man is the achiever outside the home\nand the woman takes care of the home and family",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 2021-2022")
save("reltrad_women_work.png")
all <- gss %>%
filter(year >= 2020) %>%
gss_reltrad6(reltrad) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
group_by(reltrad, gender) %>%
socsci::mean_ci(work, wt= wtssnrps, ci = .84) %>%
filter(reltrad != "NA") %>%
filter(gender != "NA")
men <- all %>%
filter(gender == "Men") %>%
select(reltrad, men = mean)
women <- all %>%
filter(gender == "Women") %>%
select(reltrad, women = mean)
lab <- left_join(men, women) %>%
mutate(diff = men - women) %>%
select(reltrad, diff) %>%
mutate(diff = round(diff, 2)) %>%
mutate(diff = diff*100) %>%
mutate(diff = paste0(diff, "%"))
ttt <- left_join(all, lab)
library(ggpubr)
ttt %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = gender, y = mean, fill = factor(gender))) +
geom_col(color = "black") +
geom_bracket(data = ttt, aes(label = diff), xmin = 1, xmax = 2, y.position = .475, label = "test", family = "font", label.size = 7, size = 1) +
facet_wrap(~ reltrad) +
theme_rb() +
scale_fill_manual(values = c("#28666e", "#5f2680")) +
scale_y_continuous(labels = percent, limits = c(0, .5)) +
geom_text(aes(y = .025, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font", color = 'white') +
theme(plot.title = element_text(size = 14)) +
labs(x = "", y = "Share Agreeing", title = "It is much better for everyone involved if the man is the achiever\noutside the home and the woman takes care of the home and family",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 2021-2022")
save("gender_reltrad_compare.png", ht = 10, wd = 6)
regg <- gss %>%
filter(year >= 2020) %>%
mutate(work = fefam) %>%
mutate(work = case_when(work == 1 | work == 2 ~ 1,
work == 3 | work == 4 ~ 0)) %>%
mutate(white = case_when(race == 1 ~ 1,
TRUE ~ 0)) %>%
mutate(male = case_when(sex == 1 ~ 1,
sex == 2 ~ 0)) %>%
mutate(rep = case_when(partyid == 4 | partyid == 5 | partyid == 6 ~ 1,
partyid <= 3 ~ 0)) %>%
gss_reltrad6(reltrad) %>%
select(work, white, male, educ, income, attend, rep, age, reltrad)
regg$reltrad <- relevel(factor(regg$reltrad), ref = "Catholic")
out <- glm(work ~ white + male + educ + income + attend + rep + age + reltrad, family = "binomial", data = regg)
library(jtools)
coef_names <- c("White" = "white",
"Income" = "income",
"Education" = "educ",
"Age" = "age",
"Male" = "male",
"Republican" = "rep",
"Church Attendance" = "attend",
"Evangelical" = "reltradEvangelical",
"Mainline" = "reltradMainline",
"Black Prot." = "reltradBlack Prot.",
"Other Faith" = "reltradOther Faith",
"No Religion" = "reltradNo Religion")
gg <- plot_summs(out, scale = TRUE, robust = "HC3", coefs = coef_names, colors = "#5f2680")
gg +
theme_rb() +
# add_text(x = -.5, y = 3.5, word = "Less Agreement", sz = 9) +
add_text(x = .85, y = 11.5, word = "More Agreement", sz = 9) +
labs(x = "", y = "", title = "It is much better for everyone involved if the man is the achiever\noutside the home and the woman takes care of the home and family",
caption = "@ryanburge + @religiondata + @religiondata\nData: General Social Survey, 2021-2022")
save("reg_women_home.png", ht = 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment