Created
June 28, 2022 13:59
-
-
Save ryanburge/f7d8515fc606075f773047a7273c7dd9 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
ggg1 <- cces08 %>% | |
filter(V215 == 1) %>% | |
cces_race(race) %>% | |
mutate(vote = CC410) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>% | |
group_by(race) %>% | |
ct(vote, wt = V201, show_na = FALSE) %>% | |
mutate(year = 2008) | |
ggg2 <- cces12 %>% | |
filter(pew_bornagain == 1) %>% | |
cces_race(race) %>% | |
mutate(vote = CC410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
group_by(race) %>% | |
ct(vote, wt = weight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2012) | |
ggg3 <- cces16 %>% | |
filter(pew_bornagain == 1) %>% | |
cces_race(race) %>% | |
mutate(vote = CC16_410a) %>% | |
mutate(vote = frcode(vote == 1 ~ "Republican", | |
vote == 2 ~ "Democrat", | |
vote == 3 | vote == 4 | vote == 5 | vote == 8 ~ "Third Party")) %>% | |
group_by(race) %>% | |
ct(vote, wt = commonweight_vv_post, show_na = FALSE) %>% | |
mutate(year = 2016) | |
ggg4 <- cces20 %>% | |
filter(pew_bornagain == 1) %>% | |
cces_race(race) %>% | |
mutate(vote = CC20_410) %>% | |
mutate(vote = frcode(vote == 1 ~ "Democrat", | |
vote == 2 ~ "Republican", | |
vote == 4 ~ "Third Party")) %>% | |
group_by(race) %>% | |
ct(vote, wt = commonpostweight, show_na = FALSE) %>% | |
mutate(year = 2020) | |
graph <- bind_rows(ggg1, ggg2, ggg3, ggg4) | |
top <- graph %>% | |
mutate(lab = round(pct, 2)) %>% | |
filter(race == "White" | race == "Black") %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_grid(year ~ race, switch = "y") + | |
scale_fill_manual(values = c("azure3", "dodgerblue3", "firebrick3")) + | |
theme_rb() + | |
# 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 = 4, family = "font", color = "black") + | |
labs(x = "", y = "", title = "Presidential Vote Choice Among Evangelicals by Race", subtitle = "", caption = "") | |
ggsave("E://vote_choice1.png", width = 9, height = 4) | |
bot <- graph %>% | |
mutate(lab = round(pct, 2)) %>% | |
filter(race == "Hispanic" | race == "Asian") %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_grid(year ~ race, switch = "y") + | |
scale_fill_manual(values = c("azure3", "dodgerblue3", "firebrick3")) + | |
theme_rb() + | |
theme(legend.position = c(.5, -.45)) + | |
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 = 4, family = "font", color = "black") + | |
labs(x = "", y = "", title = "", subtitle = "", caption = "@ryanburge\nData: CES 2008-2020") | |
ggsave("E://vote_choice2.png", width = 9, height = 4) | |
library(patchwork) | |
both <- top / bot | |
ggsave("E://patched_evan_votes.png", type = "cairo-png", both, width = 10, height = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment