Created
December 16, 2023 19:08
-
-
Save ryanburge/0e424935b7776fc95025b4684e67834f to your computer and use it in GitHub Desktop.
This file contains 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
graph <- cces %>% | |
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022) %>% | |
cces_pid3(pid7) %>% | |
mutate(religpew = religion) %>% | |
mutate(rel = frcode(religpew <= 8 ~ "Religious", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>% | |
group_by(pid3, year) %>% | |
ct(rel, wt = weight, show_na = FALSE) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") | |
graph %>% | |
mutate(year = as.factor(year)) %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = fct_rev(year), y = pct, fill = fct_rev(rel))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ pid3, ncol =2, strip.position = "top") + | |
scale_fill_manual(values = c("#FF420E", "#004586")) + | |
theme_rb() + | |
theme(legend.position = "bottom") + | |
scale_y_continuous(labels = percent) + | |
theme(strip.text.y.left = element_text(angle=0, hjust = 1)) + | |
guides(fill = guide_legend(reverse=T, nrow = 1)) + | |
# theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) + | |
theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank()) + | |
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 6, family = "font", color = "black") + | |
geom_text(aes(label = ifelse(rel == "Religious", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 6, family = "font", color = "white") + | |
theme(strip.text = element_text(size = 16)) + | |
labs(x = "", y = "", title = "The Religious Composition of Both Parties, 2008-2022", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022") | |
save("sec_lib_pid2.png", wd = 9, ht = 4) | |
graph1 <- cces22 %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(religpew <= 8 ~ "Religious", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>% | |
mutate(ab = CC22_332a) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
group_by(pid3, rel) %>% | |
mean_ci(ab, wt = commonweight, ci = .84) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") %>% | |
mutate(type = "Always Allow a Woman to Obtain An\nAbortion as a Matter of Choice") | |
graph2 <- cces22 %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(religpew <= 8 ~ "Religious", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>% | |
mutate(ab = CC22_332c) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
group_by(pid3, rel) %>% | |
mean_ci(ab, wt = commonweight, ci = .84) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") %>% | |
mutate(type = "Prohibit All Abortions After the 20th\nWeek of Pregnancy") | |
graph3 <- cces22 %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(religpew <= 8 ~ "Religious", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>% | |
mutate(ab = CC22_332e) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
group_by(pid3, rel) %>% | |
mean_ci(ab, wt = commonweight, ci = .84) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") %>% | |
mutate(type = "Prohibit Federal Funds for Abortion") | |
graph4 <- cces22 %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(religpew <= 8 ~ "Religious", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>% | |
mutate(ab = CC22_332f) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
group_by(pid3, rel) %>% | |
mean_ci(ab, wt = commonweight, ci = .84) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") %>% | |
mutate(type = "Abortion Illegal in All Circumstances") | |
all <- bind_rows(graph1, graph2, graph3, graph4) | |
library(ggh4x) | |
all %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = rel, y = mean, fill = rel)) + | |
geom_col(color = "black") + | |
facet_nested_wrap(~type + pid3, nrow = 4, ncol=4) + | |
theme_rb() + | |
y_pct() + | |
error_bar() + | |
lab_bar(top = FALSE, type = lab, pos = .055, sz = 9) + | |
geom_text(aes(y = .055, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 9, family = "font", color = "white") + | |
geom_text(aes(y = .055, label = ifelse(mean <.10, paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 9, family = "font", color = "black") + | |
scale_fill_calc() + | |
theme(strip.text = element_text(size = 16), | |
strip.placement = "outside") + # Move strip text to the top | |
labs(vars = "Type", x = "", y = "", title = "Views of Abortion by Party and Religion", caption = "@ryanburge\nData: Cooperative Election Study, 2022") | |
save("ab_all_ces22_rel_secular.png", wd = 8, ht = 12) | |
graph <- gss %>% | |
filter(year <= 2018) %>% | |
mutate(ab = abany) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(relig != 4 ~ "Religious", | |
relig == 4 ~ "Secular")) %>% | |
group_by(year, pid3, rel) %>% | |
mean_ci(ab, wt = wtssall) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") | |
graph1 <- gss %>% | |
filter(year > 2018) %>% | |
mutate(ab = abany) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(relig != 4 ~ "Religious", | |
relig == 4 ~ "Secular")) %>% | |
group_by(year, pid3, rel) %>% | |
mean_ci(ab, wt = wtssnrps) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") | |
both <- bind_rows(graph, graph1) | |
both %>% | |
ggplot(., aes(x = year, y = mean, color = rel, group = rel)) + | |
geom_point(stroke = .5, shape = 21) + | |
geom_smooth(se = FALSE) + | |
facet_wrap(~ pid3) + | |
scale_color_calc() + | |
theme_rb(legend = TRUE) + | |
y_pct() + | |
theme(strip.text = element_text(size = 20)) + | |
labs(x = "", y = "", title = "Share in Favor of Legal Abortion for Any Reason", caption = "@ryanburge\nData: General Social Survey, 1977-2022") | |
save("gss_abany_22_rel_sec_pid2.png") | |
graph <- gss %>% | |
filter(year <= 2018) %>% | |
mutate(ab = abnomore) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(relig != 4 ~ "Religious", | |
relig == 4 ~ "Secular")) %>% | |
group_by(year, pid3, rel) %>% | |
mean_ci(ab, wt = wtssall) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") | |
graph1 <- gss %>% | |
filter(year > 2018) %>% | |
mutate(ab = abnomore) %>% | |
mutate(ab = case_when(ab == 1 ~ 1, | |
ab == 2 ~ 0)) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(rel = frcode(relig != 4 ~ "Religious", | |
relig == 4 ~ "Secular")) %>% | |
group_by(year, pid3, rel) %>% | |
mean_ci(ab, wt = wtssnrps) %>% | |
na.omit() %>% | |
filter(pid3 != "Independent") | |
both <- bind_rows(graph, graph1) | |
both %>% | |
ggplot(., aes(x = year, y = mean, color = rel, group = rel)) + | |
geom_point(stroke = .5, shape = 21) + | |
geom_smooth(se = FALSE) + | |
facet_wrap(~ pid3) + | |
scale_color_calc() + | |
theme_rb(legend = TRUE) + | |
y_pct() + | |
theme(strip.text = element_text(size = 20)) + | |
labs(x = "", y = "", title = "Share in Favor of Legal Abortion If Woman Doesn't Want Any More Children", caption = "@ryanburge\nData: General Social Survey, 1977-2022") | |
save("gss_abnomore_22_rel_sec_pid2.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment