Created
January 23, 2019 01:02
-
-
Save ryanburge/fbc8c6c7dbd8837feca9c355105418c3 to your computer and use it in GitHub Desktop.
Pro Life Atheists or Pro Life Liberals
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
## Distribution of Abortion Opinion by Ideology #### | |
abg <- cces16 %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mutate(ideo3 = frcode(ideo5 == 1 | ideo5 == 2 ~ "Liberal", | |
ideo5 == 3 ~ "Moderate", | |
ideo5 == 4 | ideo5 == 5 ~ "Conservative", | |
TRUE ~ "REMOVE")) %>% | |
filter(abort != "NA") %>% | |
group_by(ideo3) %>% | |
ct(abort) | |
abg %>% | |
filter(ideo3 != "REMOVE") %>% | |
ggplot(.,aes(x = abort, y = pct, fill = ideo3)) + | |
geom_col(color = "black") + | |
facet_wrap(~ ideo3, ncol= 3) + | |
scale_fill_manual(values = c("dodgerblue3", "azure3", "firebrick3")) + | |
theme_gg("Abel") + | |
scale_y_continuous(labels = percent) + | |
labs(x = "<- More Pro-Choice:More Pro-Life -->", y = "", title = "Distribution of Abortion Opinion by Political Ideology", caption = "Data: CCES 2016") + | |
geom_text(aes(y = pct + .015, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") + | |
ggsave("D://cces/images/abort_ideo3.png") | |
## More than Two Quesstions Yes #### | |
graph <- cces16 %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mutate(prolife = recode(abort, "2:5=1; else =0")) %>% | |
mutate(nones = frcode(religpew == 1 ~ "Protestant", | |
religpew == 2 ~ "Catholic", | |
religpew == 3 ~ "Mormon", | |
religpew == 5 ~ "Jewish", | |
religpew == 6 ~ "Muslim", | |
religpew == 7 ~ "Buddhist", | |
religpew == 8 ~ "Hindu", | |
religpew == 9 ~ "Atheist", | |
religpew == 10 ~ "Agnostic", | |
religpew == 11 ~ "Nothing\nin\nParticular", | |
TRUE ~ "REMOVE")) %>% | |
filter(abort != "NA") %>% | |
group_by(nones) %>% | |
mean_ci(prolife) | |
graph1 <- cces16 %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mutate(prolife = recode(abort, "2:5=1; else =0")) %>% | |
filter(evangelical == 1) %>% | |
filter(abort != "NA") %>% | |
mean_ci(prolife) %>% | |
mutate(nones = "Evangelical") | |
graph2 <- cces16 %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mutate(prolife = recode(abort, "2:5=1; else =0")) %>% | |
filter(mainline == 1) %>% | |
filter(abort != "NA") %>% | |
mean_ci(prolife) %>% | |
mutate(nones = "Mainline") | |
graph <-bind_rows(graph, graph1, graph2) | |
showtext_opts(dpi = 300) | |
graph %>% | |
mutate(mean = round(mean, 3)) %>% | |
filter(nones != "REMOVE") %>% | |
filter(nones != "Protestant") %>% | |
ggplot(., aes(x = reorder(nones, -mean), y = mean, fill = mean)) + | |
geom_col(color = "black") + | |
scale_fill_gradient(low = "#1565C0", high = "#b92b27") + | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9)) + | |
theme_gg("Abel") + | |
scale_y_continuous(labels = percent) + | |
geom_text(aes(y = .08 , label = paste0(mean*100, '%')), position = position_dodge(width = .9), size = 4, family = "font") + | |
labs(x = "", y = "", title = "Percent Who Agree With At Least Two Pro-Life Questions", caption = "Data: CCES 2016") + | |
ggsave("D://cces/images/abortion_rel.png", width = 8) | |
## Individual Question Means #### | |
ab_fun <- function(df, var, var1){ | |
var <- enquo(var) | |
df1 <- df %>% | |
filter(religpew == 9) %>% | |
mutate(ab = recode(!! var, "1=1; 2=0; else = NA")) %>% | |
mean_ci(ab, ci = .84) %>% | |
mutate(group = " Atheist ") | |
df2 <- df %>% | |
mutate(ab = recode(!! var, "1=1; 2=0; else = NA")) %>% | |
filter(religpew == 10) %>% | |
mean_ci(ab, ci = .84) %>% | |
mutate(group = " Agnostic ") | |
bind_rows(df1, df2) %>% | |
mutate(ques = var1) | |
} | |
fff <- cces16 %>% ab_fun(CC16_332a, "Matter of\nChoice") | |
fff1 <- cces16 %>% ab_fun(CC16_332b, "Only in\nRape or Incest") | |
fff2 <- cces16 %>% ab_fun(CC16_332c, "Prohibit After\n20 Weeks") | |
fff3 <- cces16 %>% ab_fun(CC16_332d, "Employers Decline\nAbortion Coverage") | |
fff4 <- cces16 %>% ab_fun(CC16_332e, "Prohibit Federal\nFunds") | |
fff5 <- cces16 %>% ab_fun(CC16_332f, "Completely\nIllegal") | |
graph <- bind_df("fff") | |
graph %>% | |
mutate(mean = round(mean, 3)) %>% | |
ggplot(., aes(x = ques, y = mean, fill = group)) + | |
geom_col(color = "black", position = "dodge")+ | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9)) + | |
theme_gg("Abel") + | |
scale_y_continuous(labels = percent) + | |
scale_fill_manual(values = c("#A7414A", "#A37C27")) + | |
geom_text(aes(y = .08 , label = paste0(mean*100, '%')), position = position_dodge(width = .9), size = 4, family = "font") + | |
theme(legend.position = "bottom") + | |
labs(x= "", y = "Percent that Support", title = "Where Do Atheists and Agnostics Differ?", caption = "Data: CCES 2016") + | |
ggsave("D://cces/images/abort_ag_ath.png", width = 7) | |
## Abortion Importance #### | |
graph <- cces16 %>% | |
group_by(religpew) %>% | |
filter(CC16_301b <=5) %>% | |
ct(CC16_301b, wt = commonweight_vv) %>% | |
ungroup(religpew) %>% | |
mutate(religpew = frcode(religpew == 1 ~ "Protestant", | |
religpew == 2 ~ "Catholic", | |
religpew == 3 ~ "Mormon", | |
religpew == 5 ~ "Jewish", | |
religpew == 6 ~ "Muslim", | |
religpew == 7 ~ "Buddhist", | |
religpew == 8 ~ "Hindu", | |
religpew == 9 ~ "Atheist", | |
religpew == 10 ~ "Agnostic", | |
religpew == 11 ~ "Nothing\nin\nParticular", | |
TRUE ~ "REMOVE")) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) | |
graph1 <- cces16 %>% | |
filter(evangelical ==1) %>% | |
filter(CC16_301b <=5) %>% | |
ct(CC16_301b, wt = commonweight_vv) %>% | |
ungroup(religpew) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) %>% | |
mutate(religpew = "Evangelical") | |
graph2 <- cces16 %>% | |
filter(mainline ==1) %>% | |
filter(CC16_301b <=5) %>% | |
ct(CC16_301b, wt = commonweight_vv) %>% | |
ungroup(religpew) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) %>% | |
mutate(religpew = "Mainline") | |
graph <- bind_rows(graph, graph1, graph2) | |
graph %>% | |
filter(religpew != "REMOVE") %>% | |
filter(religpew != "Protestant") %>% | |
ggplot(., aes(x = CC16_301b, y = pct, fill = religpew)) + | |
geom_col(color = "black") + | |
facet_wrap(~ religpew) + | |
theme_gg("Abel") + | |
scale_fill_d3(palette = "category20") + | |
scale_y_continuous(labels = percent) + | |
theme(axis.text.x = element_text(angle = 45, hjust = 1)) + | |
geom_text(aes(y = pct + .025 , label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") + | |
labs(x = "Importance of Abortion", y = "", title = "Importance of Abortion by Religious Tradition", caption = "Data: CCES 2016") + | |
ggsave("D://cces/images/facet_abort.png", height = 8) | |
## Link Between Importance and Policy #### | |
graph1 <- cces16 %>% | |
mutate(nones = recode(religpew, "9:10 =1; else = 0")) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) %>% | |
group_by(nones, CC16_301b) %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mean_ci(abort, ci = .84) %>% | |
na.omit() %>% | |
filter(nones ==1) %>% | |
mutate(group = "Atheist/Agnostic") | |
graph2 <- cces16 %>% | |
filter(evangelical ==1) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) %>% | |
group_by(CC16_301b) %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
mean_ci(abort, ci = .84) %>% | |
na.omit() %>% | |
mutate(group = "Evangelicals") | |
graph <- bind_rows(graph1, graph2) | |
graph %>% | |
ggplot(., aes(x = mean, y = CC16_301b)) + | |
geom_point(shape=21, size =3, aes(fill = factor(group)), show.legend = TRUE) + | |
geom_errorbarh(aes(xmin = lower, xmax=upper, colour = factor(group)), height=0, size = 1, show.legend = FALSE) + | |
scale_color_manual(values = c("darkorchid", "forestgreen")) + | |
scale_fill_manual(values = c("darkorchid", "forestgreen")) + | |
theme_gg("Abel") + | |
theme(legend.position = c(0.5, 0.8)) + | |
scale_x_continuous(limits = c(0, 4)) + | |
labs(x = "<- More Pro-Choice:More Pro-Life -->", y ="Importance of Abortion", title = "Abortion Importance is Polarizing", caption = "Data: CCES 2016", subtitle = "84% Confidence Intervals") + | |
ggsave("D://cces/images/ab_imp.png", width = 7) | |
cces16 %>% | |
filter(religpew == 9 | religpew == 10) %>% | |
mutate(CC16_301b = frcode(CC16_301b == 5 ~ "No Importance", | |
CC16_301b == 4 ~ "Very Low", | |
CC16_301b == 3 ~ "Somewhat Low", | |
CC16_301b == 2 ~ "Somewhat High", | |
CC16_301b == 1 ~ "Very High")) %>% | |
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>% | |
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>% | |
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>% | |
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>% | |
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>% | |
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>% | |
filter(CC16_301b == "Very High") %>% | |
ct(abort) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment