Created
June 27, 2022 17:56
-
-
Save ryanburge/9e93a7d0a224b445c899f4f3f04865d4 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
## Figure 6 - Ideological Space #### | |
fun <- function(df, var1, var2, var3, weight, yr) { | |
aaa1 <- df %>% | |
filter({{var1}} <= 7) %>% | |
mean_ci({{var1}}, wt = {{weight}}) %>% | |
mutate(year = yr) %>% | |
mutate(group = "Yourself") | |
aaa2 <- df %>% | |
filter({{var2}} <= 7) %>% | |
mean_ci({{var2}}, wt = {{weight}}) %>% | |
mutate(year = yr) %>% | |
mutate(group = "Democrats") | |
aaa3 <- df %>% | |
filter({{var3}} <= 7) %>% | |
mean_ci({{var3}}, wt = {{weight}}) %>% | |
mutate(year = yr) %>% | |
mutate(group = "Republicans") | |
bind_rows(aaa1, aaa2, aaa3) | |
} | |
yyy1 <- cces12 %>% filter(race == 1 & evangelical == 1) %>% fun(CC334A, CC334E, CC334F, weight_vv, yr = 2012) | |
yyy2 <- cces14 %>% filter(race == 1 & evangelical == 1) %>% fun(CC334A, CC334K, CC334L, weight, yr = 2014) | |
yyy3 <- cces16 %>% filter(race == 1 & evangelical == 1) %>% fun(CC16_340a, CC16_340g, CC16_340h, commonweight, yr = 2016) | |
yyy4 <- cces17 %>% filter(race == 1 & evangelical == 1) %>% fun(CC17_350a, CC17_350d, CC17_350e, weights_common, yr = 2017) | |
yyy5 <- cces18 %>% filter(race == 1 & evangelical == 1) %>% fun(CC18_334A, CC18_334D, CC18_334E, commonweight, yr = 2018) | |
yyy6 <- cces19 %>% filter(race == 1 & evangelical == 1) %>% fun(CC19_334a, CC19_334d, CC19_334e, commonweight, yr = 2019) | |
yyy7 <- cces20 %>% filter(race == 1 & evangelical == 1) %>% fun(CC20_340a, CC20_340e, CC20_340f, commonweight, yr = 2020) | |
yyy8 <- cces21 %>% filter(race == 1 & evangelical == 1) %>% fun(CC21_330a, CC21_330e, CC21_330f, commonweight, yr = 2021) | |
graph <- bind_df("yyy") %>% | |
mutate(trad = "White Evangelicals") | |
ttt1 <- cces12 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC334A, CC334E, CC334F, weight_vv, yr = 2012) | |
ttt2 <- cces14 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC334A, CC334K, CC334L, weight, yr = 2014) | |
ttt3 <- cces16 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC16_340a, CC16_340g, CC16_340h, commonweight, yr = 2016) | |
ttt4 <- cces17 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC17_350a, CC17_350d, CC17_350e, weights_common, yr = 2017) | |
ttt5 <- cces18 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC18_334A, CC18_334D, CC18_334E, commonweight, yr = 2018) | |
ttt6 <- cces19 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC19_334a, CC19_334d, CC19_334e, commonweight, yr = 2019) | |
ttt7 <- cces20 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC20_340a, CC20_340e, CC20_340f, commonweight, yr = 2020) | |
ttt8 <- cces21 %>% filter(religpew == 9 | religpew == 10) %>% fun(CC21_330a, CC21_330e, CC21_330f, commonweight, yr = 2021) | |
graph1 <- bind_df("ttt") %>% | |
mutate(trad = "Atheists/Agnostics") | |
gg <- bind_rows(graph, graph1) | |
gg %>% | |
mutate(year = as.factor(year)) %>% | |
ggplot(., aes(x = fct_rev(year), y = mean, color = group, group = group)) + | |
geom_line() + | |
geom_errorbar(aes(ymin = lower, ymax=upper), size = 1, width = 0) + | |
geom_point(shape = 21, stroke = 2, fill = "white") + | |
coord_flip() + | |
facet_wrap(~ trad) + | |
scale_y_continuous(breaks = c(1,2,3,4,5,6,7), labels = c("Very\nLiberal", "Lib.", "", "Middle of\nthe Road", "", "Cons.", "Very\nConservative"), limits = c(1,7)) + | |
scale_color_manual(values = c("dodgerblue3", "azure3", "firebrick3")) + | |
theme_gg(legend = TRUE) + | |
labs(x = "", y = "", title = "Place Yourself, Democrats, and Republicans in Ideological Space", caption = "@ryanburge\nData: CCES 2012-2019") + | |
ggsave("E://your_self_dems_republicans.png", type = "cairo-png", height = 9) | |
# https://gist.github.com/9e93a7d0a224b445c899f4f3f04865d4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment