Last active
February 24, 2020 19:37
-
-
Save ryanburge/c28c01c2c57d4a5634ce6bc9f171f668 to your computer and use it in GitHub Desktop.
Education Evangelicals Republican
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
graph <- gss %>% | |
filter(year == 1972 | year == 2018) %>% | |
mutate(ed = frcode(educ <= 11 ~ "HS\nDropout", | |
educ == 12 ~ "HS\nGrad", | |
educ >= 13 & educ <= 15 ~ "Some\nCollege", | |
educ == 16 ~ "4 Yr.", | |
educ >= 17 ~ "Grad\nSchool")) %>% | |
gss_reltrad(reltrad) %>% | |
group_by(year, reltrad) %>% | |
ct(ed, wt = wtss) | |
graph %>% | |
filter(reltrad == "Evangelical" | reltrad == "Catholic" | reltrad == "Mainline" | reltrad == "No Religion") %>% | |
filter(ed != "NA") %>% | |
filter(reltrad != "NA") %>% | |
ungroup(year) %>% | |
mutate(year = as.factor(year)) %>% | |
ggplot(., aes(x = ed, y = pct, fill = year)) + | |
geom_col(color = "black", position = "dodge") + | |
facet_wrap(~ reltrad) + | |
theme_gg("Abel", legend = TRUE) + | |
y_pct() + | |
scale_fill_d3() + | |
lab_bar(type = pct, pos = .02, sz = 3, top = TRUE) + | |
labs(x = "", y = "", title = "Increases in Educational Attainment by Religious Groups", caption = "@ryanburge\nData: GSS 1972-2018")+ | |
ggsave("E://education_reltrad.png", type = "cairo-png") | |
graph <- gss %>% | |
filter(evangelical == 1) %>% | |
mutate(years = frcode(year <= 1979 ~ "1970's", | |
year >= 2010 ~ "2010's")) %>% | |
mutate(ed2 = frcode(educ <= 12 ~ "HS or Less", | |
educ >= 16 ~ "4 Yr or More")) %>% | |
gss_pid3(partyid) %>% | |
group_by(years, ed2) %>% | |
ct(pid3, wt = wtss, show_na = FALSE) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid3))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_grid(years ~ ed2, switch = "y") + | |
scale_fill_manual(values = c("firebrick3", "azure3", "dodgerblue3")) + | |
theme_gg("Abel") + | |
theme(legend.position = "bottom") + | |
scale_y_continuous(labels = percent) + | |
guides(fill = guide_legend(nrow = 1, reverse = TRUE)) + | |
theme(strip.text.y = element_text(angle = 180)) + | |
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 = 3.5, family = "font", color = "black") + | |
labs(x = "", y = "", title = "Partisanship by Education Level", subtitle = "Among Evangelicals", caption = "@ryanburge\nData: CCES 2018") + | |
ggsave("E://partyid_evans.png", width = 12, height = 5) | |
graph <- gss %>% | |
filter(mainline == 1) %>% | |
mutate(years = frcode(year <= 1979 ~ "1970's", | |
year >= 2010 ~ "2010's")) %>% | |
mutate(ed2 = frcode(educ <= 12 ~ "HS or Less", | |
educ >= 16 ~ "4 Yr or More")) %>% | |
gss_pid3(partyid) %>% | |
group_by(years, ed2) %>% | |
ct(pid3, wt = wtss, show_na = FALSE) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid3))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_grid(years ~ ed2, switch = "y") + | |
scale_fill_manual(values = c("firebrick3", "azure3", "dodgerblue3")) + | |
theme_gg("Abel") + | |
theme(legend.position = "bottom") + | |
scale_y_continuous(labels = percent) + | |
guides(fill = guide_legend(nrow = 1, reverse = TRUE)) + | |
theme(strip.text.y = element_text(angle = 180)) + | |
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 = 3.5, family = "font", color = "black") + | |
labs(x = "", y = "", title = "Partisanship by Education Level", subtitle = "Among Mainline", caption = "@ryanburge\nData: CCES 2018") + | |
ggsave("E://partyid_ml.png", width = 12, height = 5) | |
graph <- gss %>% | |
mutate(ed2 = frcode(educ <= 12 ~ "HS or Less", | |
educ >= 16 ~ "4 Yr or More")) %>% | |
gss_pid3(partyid) %>% | |
gss_reltrad(reltrad) %>% | |
group_by(year, ed2, reltrad) %>% | |
ct(pid3, wt = wtss, show_na = FALSE) %>% | |
na.omit() %>% | |
filter(reltrad == "Evangelical" | reltrad == "Mainline" | reltrad == "Catholic" | reltrad == "No Religion") | |
graph %>% | |
filter(pid3 == "Republican") %>% | |
ggplot(., aes(x = year, y = pct, color= reltrad, group = reltrad)) + | |
geom_point(size=3, color="white") + | |
geom_point(size=2, shape=1) + | |
geom_point(size=1, shape=19) + | |
theme_gg("Abel", legend = TRUE) + | |
y_pct() + | |
geom_smooth(se = FALSE, linetype = "twodash") + | |
scale_color_solarized() + | |
facet_wrap(~ ed2) + | |
scale_x_continuous(breaks = c(1978, 1988, 1998, 2008, 2018)) + | |
labs(x = "", y = "Percent Identifying as Republican", title = "Significant Shifts in Partisanship by Education Level", caption = "@ryanburge\nData: GSS 1972-2018") + | |
ggsave("E://ed_christian.png", type = "cairo-png") | |
#### Heat #### | |
graph <- cces18 %>% | |
mutate(trad = frcode(evangelical == 1 ~ "Evangelical", | |
mainline == 1 ~ "Mainline", | |
catholic == 1 ~ "Catholic", | |
religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones")) %>% | |
mutate(app = case_when(CC18_app_dtrmp_post ==1 | CC18_app_dtrmp_post ==2 ~ 1, | |
CC18_app_dtrmp_post ==3 | CC18_app_dtrmp_post ==4 | CC18_app_dtrmp_post == 5 ~ 0)) %>% | |
mutate(educ = frcode(educ == 1 ~ "No HS", | |
educ == 2 ~ "HS\nGrad", | |
educ == 3 ~ "Some\nCollege", | |
educ == 4 ~ "2 Yr.\nDegree", | |
educ == 5 ~ "4 Yr.\nDegree", | |
educ == 6 ~ "Grad\nSchool")) %>% | |
group_by(trad, educ) %>% | |
mean_ci(app, wt = commonpostweight) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x= educ, y = trad)) + | |
geom_tile(aes(fill = mean), color = "black") + | |
scale_fill_gradient2(low = "dodgerblue3", mid = "azure3", high = "firebrick3", midpoint = .55) + | |
theme_gg("Abel") + | |
geom_text(aes(x= educ, y = trad, label = paste0(mean*100, '%')), size = 4, family = "font") + | |
labs(y= "Religious Tradition", x = "Highest Level of Education", title = "Percent Approving of Trump", subtitle = "", caption = "@ryanburge\nData: CCES 2018") + | |
ggsave("heat_educ.png", width = 6, type = "cairo-png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment