-
-
Save ryanburge/17d3b11f6ce4fc325e409e197d44a6c7 to your computer and use it in GitHub Desktop.
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
| one <- gss %>% | |
| filter(year == 2004) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year) %>% | |
| mean_ci(mar, wt = wtssall) | |
| two <- gss %>% | |
| mutate(mar = case_when(marhomo1 == 1 | marhomo1 == 2 ~ 1, | |
| marhomo1 == 3 | marhomo1 == 4 | marhomo1 == 5 ~ 0)) %>% | |
| group_by(year) %>% | |
| mean_ci(mar, wt = wtssall) %>% na.omit() | |
| three <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year) %>% | |
| mean_ci(mar, wt = wtssnrps) %>% na.omit() | |
| graph <- bind_rows(two, three) | |
| graph %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = mean, fill = mean)) + | |
| geom_col(color = "black") + | |
| theme_rb() + | |
| y_pct() + | |
| geom_text(aes(y = mean + .03, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") + | |
| scale_fill_gradient2(low = "firebrick1", mid = "darkorchid", "dodgerblue1", midpoint = .4) + | |
| labs(x = "Year", y = "Share Agreeing", title = "Homosexual couples should have the right to marry one another", caption = "@ryanburge\nData: General Social Survey, 2004-2022") | |
| save("marhomo_gss22_all.png", wd = 7) | |
| one <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| filter(year == 2004) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(mar, wt = wtssall) | |
| two <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(mar = case_when(marhomo1 == 1 | marhomo1 == 2 ~ 1, | |
| marhomo1 == 3 | marhomo1 == 4 | marhomo1 == 5 ~ 0)) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(mar, wt = wtssall) %>% na.omit() | |
| three <- gss %>% | |
| filter(year >= 2021) %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(mar, wt = wtssnrps) %>% na.omit() | |
| graph <- bind_rows(one, two, three) %>% filter(reltrad != "NA") | |
| graph %>% | |
| ggplot(., aes(x = year, y = mean, color = reltrad, group = reltrad)) + | |
| geom_point(stroke = 1, shape = 21, alpha = .45) + | |
| geom_smooth(se = FALSE) + | |
| facet_wrap(~ reltrad) + | |
| theme_rb() + | |
| y_pct() + | |
| theme(strip.text = element_text(size = 20)) + | |
| scale_color_manual(values = c(met.brewer("Johnson", 6))) + | |
| labs(x = "Year", y = "Share Agreeing", title = "Homosexual couples should have the right to marry one another", caption = "@ryanburge\nData: General Social Survey, 2004-2022") | |
| save("marhomo_gss22_reltrad.png") | |
| one <- gss %>% | |
| mutate(pid7 = partyid + 1) %>% | |
| cces_pid3(pid7) %>% | |
| filter(year == 2004) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, pid3) %>% | |
| mean_ci(mar, wt = wtssall) | |
| two <- gss %>% | |
| mutate(pid7 = partyid + 1) %>% | |
| cces_pid3(pid7) %>% | |
| mutate(mar = case_when(marhomo1 == 1 | marhomo1 == 2 ~ 1, | |
| marhomo1 == 3 | marhomo1 == 4 | marhomo1 == 5 ~ 0)) %>% | |
| group_by(year, pid3) %>% | |
| mean_ci(mar, wt = wtssall) %>% na.omit() | |
| three <- gss %>% | |
| filter(year >= 2021) %>% | |
| mutate(pid7 = partyid + 1) %>% | |
| cces_pid3(pid7) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, pid3) %>% | |
| mean_ci(mar, wt = wtssnrps) %>% na.omit() | |
| graph <- bind_rows(one, two, three) %>% filter(pid3 != "NA") | |
| graph %>% | |
| 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 = .5) + | |
| theme_rb() + | |
| y_pct() + | |
| pid3_color() + | |
| labs(x = "Year", y = "Share Agreeing", title = "Homosexual couples should have the right to marry one another", caption = "@ryanburge\nData: General Social Survey, 2004-2022") | |
| save("marhomo_gss22_pid3.png") | |
| gg <- graph %>% | |
| filter(pid3 %in% c("Democrat", "Republican")) %>% | |
| group_by(year) %>% | |
| summarize( | |
| difference = mean[pid3 == "Republican"] - mean[pid3 == "Democrat"] | |
| ) | |
| gg %>% | |
| mutate(lab = round(difference*-1, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = difference*-1, fill = difference*-1)) + | |
| geom_col(color = 'black') + | |
| theme_rb() + | |
| geom_text(aes(y = difference*-1 + .015, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 9, family = "font") + | |
| y_pct() + | |
| theme(axis.text.x = element_text(size = 20)) + | |
| scale_fill_gradient(low = "purple", high = "dodgerblue1") + | |
| labs(x = "", y = "", title = "The Difference in Democrat Support for SSM vs Republicans", | |
| caption = "@ryanburge\nData: GSS 2004-2022") | |
| save("ssm_support_pid2.png") | |
| one <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| filter(year == 2018) %>% | |
| filter(reltrad == "Evangelical" | reltrad == "Catholic" | reltrad == "Mainline") %>% | |
| mutate(att = frcode(attend == 6 | attend == 7 | attend == 8 ~ "Weekly", | |
| attend <= 5 ~ "Less Often")) %>% | |
| mutate(mar = case_when(marhomo1 == 1 | marhomo1 == 2 ~ 1, | |
| marhomo1 == 3 | marhomo1 == 4 | marhomo1 == 5 ~ 0)) %>% | |
| group_by(year, reltrad, att) %>% | |
| mean_ci(mar, wt = wtssall, ci = .84) %>% na.omit() | |
| two <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| filter(year >= 2021) %>% | |
| filter(reltrad == "Evangelical" | reltrad == "Catholic" | reltrad == "Mainline") %>% | |
| mutate(att = frcode(attend == 6 | attend == 7 | attend == 8 ~ "Weekly", | |
| attend <= 5 ~ "Less Often")) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, reltrad, att) %>% | |
| mean_ci(mar, wt = wtssnrps, ci = .84) %>% na.omit() | |
| graph <- bind_rows(one, two) | |
| graph %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = mean, fill = fct_rev(att))) + | |
| geom_col(color = "black", position = "dodge") + | |
| facet_wrap(~ reltrad) + | |
| theme_rb(legend = TRUE) + | |
| y_pct() + | |
| error_bar() + | |
| scale_fill_calc() + | |
| theme(strip.text = element_text(size = 20)) + | |
| lab_bar(top = FALSE, type = lab, pos = .04, sz = 5) + | |
| geom_text(aes(y = .04, label = ifelse(att == "Less Often", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 5, family = "font", color = 'white') + | |
| labs(x = "Year", y = "Share Agreeing", title = "Homosexual couples should have the right to marry one another - by Church Attendance", caption = "@ryanburge\nData: General Social Survey, 2004-2022") | |
| save("ssm_support_att_reltrad.png") | |
| one <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| filter(year == 2018) %>% | |
| filter(reltrad == "Evangelical" | reltrad == "Catholic" | reltrad == "Mainline") %>% | |
| mutate(age2 = frcode(age <= 39 ~ "18-39", | |
| age >= 40 ~ "40+")) %>% | |
| mutate(mar = case_when(marhomo1 == 1 | marhomo1 == 2 ~ 1, | |
| marhomo1 == 3 | marhomo1 == 4 | marhomo1 == 5 ~ 0)) %>% | |
| group_by(year, reltrad, age2) %>% | |
| mean_ci(mar, wt = wtssall, ci = .84) %>% na.omit() | |
| two <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| filter(year >= 2021) %>% | |
| filter(reltrad == "Evangelical" | reltrad == "Catholic" | reltrad == "Mainline") %>% | |
| mutate(age2 = frcode(age <= 39 ~ "18-39", | |
| age >= 40 ~ "40+")) %>% | |
| mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1, | |
| marhomo == 3 | marhomo == 4 | marhomo == 5 ~ 0)) %>% | |
| group_by(year, reltrad, age2) %>% | |
| mean_ci(mar, wt = wtssnrps, ci = .84) %>% na.omit() | |
| graph <- bind_rows(one, two) | |
| graph %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = mean, fill =age2)) + | |
| geom_col(color = "black", position = "dodge") + | |
| facet_wrap(~ reltrad) + | |
| theme_rb(legend = TRUE) + | |
| y_pct() + | |
| error_bar() + | |
| scale_fill_wsj() + | |
| theme(strip.text = element_text(size = 20)) + | |
| lab_bar(top = FALSE, type = lab, pos = .04, sz = 5) + | |
| theme(legend.text = element_text(size = 20)) + | |
| geom_text(aes(y = .04, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 5, family = "font", color = 'white') + | |
| labs(x = "Year", y = "Share Agreeing", title = "Homosexual couples should have the right to marry one another - by Age", caption = "@ryanburge\nData: General Social Survey, 2004-2022") | |
| save("ssm_support_age2_reltrad.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment