-
-
Save ryanburge/c56feaca4d06e624d92be610a7a4724b 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
gg <- cces %>% | |
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022 | year == 2023) %>% | |
group_by(year) %>% | |
filter(race == 1) %>% | |
filter(pew_bornagain == 1) %>% | |
cces_id5(ideo5) %>% | |
ct(id5, wt = weight, show_na = FALSE) | |
colors <- c("Very Liberal" = "#B2182B", | |
"Liberal" = "#EF8A62", | |
"Moderate" = "azure4", | |
"Conservative" = "#67A9CF", | |
"Very Conservative" = "#2166AC") | |
gg %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(id5))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ year, ncol =1, strip.position = "left") + | |
theme_rb() + | |
scale_fill_manual(values = colors) + | |
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(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") + | |
theme(plot.title = element_text(size = 16)) + | |
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
labs(x = "", y = "", title = "The Ideological Composition of White Evangelicals", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
save("id5_wev.png", wd = 9, ht = 5) | |
cces_id5 <- function(df, var){ | |
df %>% | |
mutate(id5 = frcode({{var}} == 1 | {{var}} == 2 ~ "Liberal", | |
{{var}} == 3 ~ "Moderate", | |
{{var}} == 4 | {{var}} == 5 ~ "Conservative")) | |
} | |
ggg1 <- cces08 %>% | |
filter(evangelical == 1) %>% | |
filter(race == 1) %>% | |
cces_id5(V243) %>% | |
mutate(vote = CC410) %>% | |
group_by(id5) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>% | |
ct(vote, wt = V201, show_na = FALSE) %>% | |
mutate(year = 2008) | |
ggg2 <- cces12 %>% | |
filter(evangelical == 1) %>% | |
filter(race == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
ct(vote, wt = weight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2012) | |
ggg3 <- cces16 %>% | |
filter(evangelical == 1) %>% | |
filter(race == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC16_410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 8 ~ "Third Party")) %>% | |
ct(vote, wt = commonweight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2016) | |
ggg4 <- cces20 %>% | |
filter(CL_voter_status <= 5) %>% | |
filter(race == 1) %>% | |
filter(pew_bornagain == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC20_410) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
ct(vote, wt = vvweight_post, show_na = FALSE) %>% | |
mutate(year = 2020) | |
all1 <- bind_rows(ggg1, ggg2, ggg3, ggg4) %>% filter(id5 != 'NA') %>% | |
mutate(type = "White Evangelicals") | |
cces_id5 <- function(df, var){ | |
df %>% | |
mutate(id5 = frcode({{var}} == 1 | {{var}} == 2 ~ "Liberal", | |
{{var}} == 3 ~ "Moderate", | |
{{var}} == 4 | {{var}} == 5 ~ "Conservative")) | |
} | |
ggg1 <- cces08 %>% | |
filter(race == 1) %>% | |
cces_id5(V243) %>% | |
mutate(vote = CC410) %>% | |
group_by(id5) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>% | |
ct(vote, wt = V201, show_na = FALSE) %>% | |
mutate(year = 2008) | |
ggg2 <- cces12 %>% | |
filter(race == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
ct(vote, wt = weight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2012) | |
ggg3 <- cces16 %>% | |
filter(race == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC16_410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 8 ~ "Third Party")) %>% | |
ct(vote, wt = commonweight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2016) | |
ggg4 <- cces20 %>% | |
filter(CL_voter_status <= 5) %>% | |
filter(race == 1) %>% | |
cces_id5(ideo5) %>% | |
group_by(id5) %>% | |
mutate(vote = CC20_410) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
ct(vote, wt = vvweight_post, show_na = FALSE) %>% | |
mutate(year = 2020) | |
all2 <- bind_rows(ggg1, ggg2, ggg3, ggg4) %>% filter(id5 != 'NA') %>% | |
mutate(type = "All White Voters") | |
graph <- bind_rows(all1, all2) | |
c3 <- c("Republican" = "#B2182B", | |
"Third Party" = "azure4", | |
"Democrat" = "#2166AC") | |
graph %>% | |
filter(id5 == "Moderate") %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = fct_rev(type), y = pct, fill = fct_rev(vote))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ year, ncol =1, strip.position = "top") + | |
theme_rb() + | |
scale_fill_manual(values = c3) + | |
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)) + | |
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
theme(plot.title = element_text(size = 16)) + | |
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
theme(strip.text.x.top = element_text(size = 22)) + | |
labs(x = "", y = "", title = "Vote Choice Among Ideologically Moderate White Respondents", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2020") | |
save("moderate_wev_presvote20.png", wd = 9, ht = 7) | |
gg <- cces %>% | |
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022 | year == 2023) %>% | |
group_by(year) %>% | |
filter(pew_bornagain == 1) %>% | |
filter(race == 1) %>% | |
filter(ideo5 == 3) %>% | |
cces_pid3(pid7) %>% | |
ct(pid3, show_na = FALSE, wt = weight) | |
c3 <- c("Republican" = "#B2182B", | |
"Independent" = "azure4", | |
"Democrat" = "#2166AC") | |
gg %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid3))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ year, ncol =1, strip.position = "left") + | |
theme_rb() + | |
scale_fill_manual(values = c3) + | |
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(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
theme(plot.title = element_text(size = 16)) + | |
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
labs(x = "", y = "", title = "The Partisan Composition of Moderate White Evangelicals", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
save("id3_moderate_wev.png", wd = 9, ht = 5) | |
cces_id3 <- function(df, var){ | |
df %>% | |
mutate(id3 = frcode({{var}} == 1 | {{var}} == 2 ~ "Liberal", | |
{{var}} == 3 ~ "Moderate", | |
{{var}} == 4 | {{var}} == 5 ~ "Conservative")) | |
} | |
aaa1 <- cces23 %>% | |
filter(pew_bornagain == 1) %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_323a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "White Evangelicals") | |
aaa2 <- cces23 %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_323a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "All White Sample") | |
yyy1 <- bind_rows(aaa1, aaa2) %>% mutate(ques = "Pathway to Citizenship") | |
aaa1 <- cces23 %>% | |
filter(pew_bornagain == 1) %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_324a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "White Evangelicals") | |
aaa2 <- cces23 %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_324a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "All White Sample") | |
yyy2 <- bind_rows(aaa1, aaa2) %>% mutate(ques = "Allow Abortion as a Choice") | |
aaa1 <- cces23 %>% | |
filter(pew_bornagain == 1) %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_328f) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "White Evangelicals") | |
aaa2 <- cces23 %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_328f) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "All White Sample") | |
yyy3 <- bind_rows(aaa1, aaa2) %>% mutate(ques = "Forgive $20K/Person in Student Loans") | |
aaa1 <- cces23 %>% | |
filter(pew_bornagain == 1) %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_343a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "White Evangelicals") | |
aaa2 <- cces23 %>% | |
filter(race == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
mutate(imm = CC23_343a) %>% | |
mutate(imm = case_when(imm == 1 ~ 1, | |
imm == 2 ~ 0)) %>% | |
group_by(id3) %>% | |
mean_ci(imm, wt = commonweight, ci = .84) %>% | |
filter(id3 != "NA") %>% | |
mutate(type = "All White Sample") | |
yyy4 <- bind_rows(aaa1, aaa2) %>% mutate(ques = "Ban Gender Transition for Children") | |
all <- bind_rows(yyy1, yyy2, yyy3, yyy4) | |
all %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = id3, y = mean, fill = type)) + | |
geom_col(color = "black", position = "dodge") + | |
facet_wrap(~ ques) + | |
theme_rb(legend = TRUE) + | |
y_pct() + | |
scale_fill_calc() + | |
geom_text(aes(y = .07, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 5, family = "font", color = 'white') + | |
error_bar() + | |
labs(x = "", y = "", title = "How Do White Evangelicals Differ from All White Americans?", caption = "@ryanburge\nData: Cooperative Election Study, 2023") | |
save("white_ev_public_opinion.png", wd = 6.25) | |
graph <- cces20 %>% | |
filter(CL_voter_status <= 5) %>% | |
filter(race == 1) %>% | |
filter(pew_bornagain == 1) %>% | |
cces_id3(ideo5) %>% | |
group_by(id3) %>% | |
cces_attend(pew_churatd) %>% | |
mutate(vote = CC20_410) %>% | |
mutate(vote = case_when(vote == 2 ~ 1, | |
vote == 1 ~ 0)) %>% | |
group_by(att, id3) %>% | |
mean_ci(vote, wt = commonweight, ci = .84) %>% filter(id3 != 'NA') %>% filter(att != "NA") | |
graph %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = att, y = mean, fill = id3)) + | |
geom_col(color = "black", position = "dodge") + | |
theme_rb(legend = TRUE) + | |
error_bar() + | |
pid3_fill() + | |
y_pct() + | |
geom_text(aes(y = .05, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 5, family = "font", color = "white") + | |
geom_text(aes(y = .05, label = ifelse(id3 == "Liberal", paste0(lab*100, '%'), '')), position = position_dodge(width = .9), size = 5, family = "font", color = "black") + | |
labs(x = "Church Attendance", y = "", title = "Two Party Vote for Trump by Ideology and Attendance - Among White Evangelicals", | |
caption = "@ryanburge\nData: Cooperative Election Study, 2020") | |
save("trump_vote_wev_id3_att.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment