-
-
Save ryanburge/d4bd07b1d631c1b0ae886c8b35075474 to your computer and use it in GitHub Desktop.
Abortion in 2020
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
fun <- function(df, var, name) | |
{ | |
df %>% | |
mutate(xtn = case_when(religion == 1 | religion == 5 ~ 1, TRUE ~ 0)) %>% | |
mutate(white = case_when(race_ethnicity == 1 & hispanic == 1 ~ 1, TRUE ~ 0 )) %>% | |
mutate(trad = frcode(xtn == 1 & is_evangelical == 1 & white == 1 ~ "White Evangelical", | |
xtn == 1 & is_evangelical == 1 & white == 0 ~ "Non-White Evangelical", | |
xtn == 1 & is_evangelical == 2 ~ "Non-Evangelical Prot.", | |
religion == 2 ~ "Catholic", | |
religion == 3 ~ "Mormon", | |
religion == 4 ~ "Orthodox", | |
religion == 6 ~ "Jewish", | |
religion == 7 ~ "Muslim", | |
religion == 8 ~ "Buddhist", | |
religion == 9 ~ "Hindu", | |
religion == 10 ~ "Atheist", | |
religion == 11 ~ "Agnostic", | |
religion == 12 ~ "Nothing in Particular", | |
religion == 13 ~ "Something Else")) %>% | |
mutate(ab = case_when({{var}} == 1 ~ 1, | |
{{var}} == 2 ~ 0)) %>% | |
group_by(trad) %>% | |
mean_ci(ab, wt = weight, ci = .84) %>% | |
mutate(type = name) %>% | |
na.omit() | |
} | |
yyy1 <- ns %>% fun(abortion_any_time, "Permit Abortion Anytime") | |
yyy2 <- ns %>% fun(abortion_never, "Never Permit Abortion") | |
yyy3 <- ns %>% fun(abortion_conditions, "Permit For Rape, Incest, Life of Mother") | |
yyy4 <- ns %>% fun(late_term_abortion, "Permit Late Term") | |
yyy5 <- ns %>% fun(abortion_insurance, "Permit Employers to\nNot Cover Abortion in Insurance") | |
yyy6 <- ns %>% fun(abortion_waiting, "Require Waiting Period/Ultrasound") | |
graph <- bind_df("yyy") | |
graph %>% | |
ggplot(., aes(x = trad, y = mean, fill = trad)) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ type) + | |
theme_rb() + | |
y_pct() + | |
error_bar() + | |
scale_fill_tableau(palette = "Tableau 20") + | |
lab_bar(top = FALSE, type = mean, pos = .07, sz = 3) + | |
labs(x = "", y = "Share in Favor", title = "Support for Abortion by Religious Tradition", caption = "@ryanburge\nData: Nationscape 2019-2020") + | |
ggsave("E://ab_facets_ns.png", type = "cairo-png", height = 6) | |
regg <- ns %>% | |
mutate(xtn = case_when(religion == 1 | religion == 5 ~ 1, TRUE ~ 0)) %>% | |
mutate(white = case_when(race_ethnicity == 1 & hispanic == 1 ~ 1, TRUE ~ 0 )) %>% | |
mutate(trad = frcode(xtn == 1 & is_evangelical == 1 & white == 1 ~ "White Evangelical", | |
xtn == 1 & is_evangelical == 1 & white == 0 ~ "Non-White Evangelical", | |
xtn == 1 & is_evangelical == 2 ~ "Non-Evangelical Prot.", | |
religion == 2 ~ "Catholic", | |
religion == 3 ~ "Mormon", | |
religion == 4 ~ "Orthodox", | |
religion == 6 ~ "Jewish", | |
religion == 7 ~ "Muslim", | |
religion == 8 ~ "Buddhist", | |
religion == 9 ~ "Hindu", | |
religion == 10 ~ "Atheist", | |
religion == 11 ~ "Agnostic", | |
religion == 12 ~ "Nothing in Particular", | |
religion == 13 ~ "Something Else")) %>% | |
mutate(any = case_when(abortion_any_time == 1 ~ 1, abortion_any_time == 2 ~ 0)) %>% | |
mutate(never = case_when(abortion_never == 1 ~ 1, abortion_never == 2 ~ 0)) %>% | |
mutate(male = case_when(gender == 2 ~ 1, gender == 1 ~ 0)) %>% | |
cces_pid3(pid7) %>% | |
mutate(ed = frcode(education == 1 | education == 2 | education == 3 ~ "Less than HS", | |
education == 4 ~ "HS Grad", | |
education == 5 | education == 6 ~ "Some College", | |
education == 7 ~ "2 Yr", | |
education == 8 ~ "4 Yr", | |
education >= 9 ~ "Graduate")) %>% | |
mutate(education = case_when(education == 1 | education == 2 | education == 3 ~ 1, | |
education == 4 ~ 2, | |
education == 5 | education == 6 ~ 3, | |
education == 7 ~ 4, | |
education == 8 ~ 5, | |
education >= 9 ~ 6)) %>% | |
select(age, male, income = household_income, education, ed, white, trad, any, never, pid3) %>% | |
na.omit() %>% | |
as_tibble() | |
lab <- regg %>% ct(trad) | |
reg1 <- glm(any ~ education*trad*pid3 + age + male + income + white, data = regg, family = "binomial") | |
gg <- interact_plot(reg1, pred= education, modx = pid3, mod2 = trad, int.width = .76, interval = TRUE, mod2.labels = lab$trad) | |
gg + | |
pid3_fill() + | |
pid3_color() + | |
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Less\nthan\nHS", "HS\nGrad", "Some\nColl", "2 Yr.", "4 Yr.", "Grad.")) + | |
y_pct() + | |
theme_rb() + | |
theme(legend.position = c(.75, .05)) + | |
labs(x = "", y = "Estimate of Support", title = "Interaction of Partisanship, Religion, and Education on Abortion Policy", | |
subtitle = "Permit abortion at any time during the pregnancy", caption = '@ryanburge\nData: Nationscape 2019-2020') + | |
ggsave("E://abortion_any_interact.png", type = 'cairo-png', height = 8) | |
reg1 <- glm(never ~ education*trad*pid3 + age + male + income + white, data = regg, family = "binomial") | |
gg <- interact_plot(reg1, pred= education, modx = pid3, mod2 = trad, int.width = .76, interval = TRUE, mod2.labels = lab$trad) | |
gg + | |
pid3_fill() + | |
pid3_color() + | |
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Less\nthan\nHS", "HS\nGrad", "Some\nColl", "2 Yr.", "4 Yr.", "Grad.")) + | |
y_pct() + | |
theme_rb() + | |
theme(legend.position = c(.75, .05)) + | |
labs(x = "", y = "Estimate of Support", title = "Interaction of Partisanship, Religion, and Education on Abortion Policy", | |
subtitle = "Never permit abortion", caption = '@ryanburge\nData: Nationscape 2019-2020') + | |
ggsave("E://abortion_never_interact.png", type = 'cairo-png', height = 8) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment