Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created August 3, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/750f79d09829465a7ac97cf227947e79 to your computer and use it in GitHub Desktop.
Save ryanburge/750f79d09829465a7ac97cf227947e79 to your computer and use it in GitHub Desktop.
Conservative Atheists
## Graph 1 ####
gg <- cces18 %>%
filter(race == 1) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 & race == 1 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
group_by(trad2) %>%
ct(ideo, wt = commonpostweight, show_na = FALSE) %>%
na.omit()
lvl <- gg %>%
filter(ideo == "Very Conservative" | ideo == "Conservative") %>%
group_by(trad2) %>%
summarise(sum = sum(pct)) %>%
arrange(-sum) %>%
select(trad2, sort = sum)
gg <- left_join(gg, lvl)
gg$trad2 <- fct_reorder(gg$trad2, gg$sort, .desc = TRUE)
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(ideo))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ trad2, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("#B2182B","#EF8A62","azure4", "#67A9CF", "#2166AC")) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 5, family = "font", color = "black") +
labs(x = "", y = "", title = "Ideological Distribution of Religious Traditions", subtitle = "White Respondents Only", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://ideo_trad2_cces.png", width = 9, height = 4)
gg <- cces18 %>%
filter(race == 1) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 & race == 1 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
mutate(ab = case_when(CC18_321a == 1 ~ 1,
CC18_321a == 2 ~ 0)) %>%
group_by(trad2, ideo) %>%
mean_ci(ab, ci = .84, wt = commonweight) %>%
na.omit()
gg %>%
ggplot(., aes(x = trad2, y = mean, fill = trad2)) +
geom_col(color = "black") +
facet_wrap(~ ideo) +
coord_flip() +
error_bar() +
scale_fill_paletteer_d("ggsci::category20_d3") +
y_pct() +
theme_gg("Abel") +
lab_bar(top = FALSE, type = mean, pos = .1, sz = 3) +
labs(x = "", y = "", title = "Support for Abortion on Demand by Ideology", caption = "@ryanburge\nData: CCES 2018", subtitle = "White Respondents Only") +
ggsave("E://ab_demand_ideo5.png", type = "cairo-png")
gg <- cces18 %>%
filter(race == 1) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 & race == 1 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
mutate(imm = case_when(CC18_322c_new == 1 ~ 1,
CC18_322c_new == 2 ~ 0)) %>%
group_by(trad2, ideo) %>%
mean_ci(imm, ci = .84, wt = commonweight) %>%
na.omit()
gg %>%
ggplot(., aes(x = trad2, y = mean, fill = trad2)) +
geom_col(color = "black") +
facet_wrap(~ ideo) +
coord_flip() +
error_bar() +
scale_fill_paletteer_d("ggsci::category20_d3") +
y_pct() +
theme_gg("Abel") +
lab_bar(top = FALSE, type = mean, pos = .1, sz = 3) +
labs(x = "", y = "", title = "Eliminating Visa Lottery and Chain Migration", caption = "@ryanburge\nData: CCES 2018", subtitle = "White Respondents Only") +
ggsave("E://imm_ideo5.png", type = "cairo-png")
gg1 <- cces18 %>%
filter(race == 1) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 & race == 1 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
group_by(trad2, ideo) %>%
mutate(vote = CC18_317) %>%
mutate(vote = frcode(vote == 1 ~ "Trump",
vote == 2 ~ "Clinton",
vote == 3 ~ "Someone Else")) %>%
ct(vote, show_na = FALSE, wt = commonpostweight) %>%
na.omit()
gg1 %>%
filter(ideo == "Very Conservative") %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ trad2, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("azure3", "dodgerblue3", "firebrick3")) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Vote Choice in 2016 Among Very Conservatives", subtitle = "White Respondents Only", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://vcon.png", width = 9, height = 4)
gg1 %>%
filter(ideo == "Very Liberal") %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ trad2, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("azure3", "dodgerblue3", "firebrick3")) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Vote Choice in 2016 Among Very Liberals", subtitle = "White Respondents Only", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://vlib.png", width = 9, height = 4)
reg <- cces18 %>%
filter(race == 1) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 & race == 1 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
filter(ideo5 <= 5) %>%
mutate(age = 2018 - birthyr) %>%
mutate(att = car::recode(pew_churatd, "6=1; 5=2; 4=3; 3=4; 2=5; 1=6; else = NA")) %>%
mutate(male = case_when(gender == 1 ~ 1, TRUE ~ 0)) %>%
mutate(vote = CC18_317) %>%
mutate(vote = case_when(vote == 1 ~ 1,
vote == 2 | vote == 3 ~ 0)) %>%
mutate(inc = car::recode(faminc_new, "97= NA")) %>%
select(trad2, ideo5, age, att, male, vote, educ, inc)
reg1 <- glm(vote ~ trad2*ideo5 + age + att + male + educ + inc, family = "binomial", data = reg)
int <- interact_plot(reg1, pred= ideo5, modx = trad2, int.width = .76, interval = TRUE)
int +
y_pct() +
theme_gg("Abel") +
theme(legend.position = c(.75, .25)) +
scale_x_continuous(breaks = c(1,2,3,4,5), labels = c("Very\nLiberal", "Liberal", "Moderate", "Conservative", "Very\nConservative")) +
labs(x = "Ideology", y = "Pr(Trump Vote in 2016)", title = "The Impact of Ideology on a Trump Vote by Religious Tradition", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://interact_ideo5_trad2.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment