Instantly share code, notes, and snippets.

Embed
What would you like to do?
White Evangelical Women with College Degrees
## Ridgeline Graph ####
font_add_google("Abel", "font")
showtext_auto()
cces16 %>%
filter(pid7 <= 7) %>%
filter(race ==1) %>%
filter(gender ==2) %>%
filter(educ ==5 | educ ==6) %>%
mutate(evangelical = recode(evangelical, "1 = 'Evangelical'; 0 = 'Non-Evangelical'")) %>%
ggplot(., aes(x = pid7, y = factor(evangelical), fill = ..x..)) +
geom_density_ridges_gradient(rel_min_height=.02) +
scale_fill_gradient2(low="dodgerblue3", high="firebrick3", mid="white", midpoint=4) +
theme_minimal() +
theme(text=element_text(size=44, family="font")) +
scale_x_continuous(limits = c(-.5,9), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Strong Democrat", "Lean Democrat", "Independent", "Lean Republican", "Not Strong Republican", "Strong Republican")) +
labs(x="Party Identification", y="", title="Distribution of Partisanship", subtitle = "Among White College-Educated Women", caption="Data: CCES 2016") +
theme(legend.position = "none") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
ggsave("D://pid_ridges_cces.png")
## Bar Graph ####
evan <- cces16 %>%
filter(evangelical ==1) %>%
filter(race ==1) %>%
filter(gender ==2) %>%
filter(educ ==5 | educ ==6) %>%
filter(CC16_410a < 3) %>%
ct(CC16_410a, wt = commonweight_vv_post) %>%
mutate(group = "Evangelicals")
not_evan <- cces16 %>%
filter(evangelical !=1) %>%
filter(race ==1) %>%
filter(gender ==2) %>%
filter(educ ==5 | educ ==6) %>%
filter(CC16_410a < 3) %>%
ct(CC16_410a, wt = commonweight_vv_post) %>%
mutate(group = "Not Evangelical")
graph <- bind_df("evan")
graph <- graph %>%
mutate(CC16_410a = recode(CC16_410a, "1 = 'Trump'; 2= 'Clinton'; 3 = 'Johnson'; 4 = 'Stein'; 5:8 = NA"))
font_add_google("Abel", "font")
showtext_auto()
graph %>%
filter(CC16_410a != "NA") %>%
ggplot(., aes(x= CC16_410a, y = pct, fill = CC16_410a)) +
geom_col(color = "black") +
facet_grid(. ~ group) +
geom_text(aes(y = pct + .025, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 14, family = "font") +
theme_minimal() +
scale_fill_manual(values = c("dodgerblue3", "firebrick3")) +
theme(legend.position = "none") +
scale_y_continuous(labels = percent) +
labs(x = "", y = "", title = "Vote Choice for College-Educated White Women", caption = "Data: CCES 2016") +
theme(text=element_text(size=44, family="font")) +
ggsave("D://college_white_wmn_vote16_2party.png")
## Ribbon Chart ####
female_eee <- gss %>%
filter(evangelical == 1) %>%
filter(race ==1) %>%
filter(sex ==2) %>%
filter(educ >=16) %>%
filter(partyid <=6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(type = "Evangelical") %>%
mutate(gender = "Female")
female_not_eee <- gss %>%
filter(evangelical != 1) %>%
filter(race ==1) %>%
filter(sex ==2) %>%
filter(educ >=16) %>%
filter(partyid <=6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(type = "Not Evangelical") %>%
mutate(gender = "Female")
male_eee <- gss %>%
filter(evangelical == 1) %>%
filter(race ==1) %>%
filter(sex ==1) %>%
filter(educ >=16) %>%
filter(partyid <=6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(type = "Evangelical") %>%
mutate(gender = "Male")
male_not_eee <- gss %>%
filter(evangelical != 1) %>%
filter(race ==1) %>%
filter(sex ==1) %>%
filter(educ >=16) %>%
filter(partyid <=6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(type = "Not Evangelical") %>%
mutate(gender = "Male")
graph <- bind_df("eee")
graph <- graph %>%
mutate(new = paste(type, gender, sep = " - "))
font_add_google("Abel", "font")
showtext_auto()
graph %>%
ggplot(., aes(x= year, y = mean, group = new, color = new)) +
geom_line() +
geom_ribbon(aes(ymin=lower, ymax=upper, color = new, fill = new), alpha = .05, size = .005, show.legend = FALSE) +
theme_minimal() +
theme(text=element_text(size=45, family="font")) +
scale_color_manual(values=c("#EE82EE", "dodgerblue3", "forestgreen", "firebrick1")) +
scale_fill_manual(values=c("#EE82EE", "dodgerblue3", "forestgreen", "firebrick1")) +
labs(x ="", y = "", title = "Change in Party Identification", subtitle = "For White Respondents with a College Education", caption = "Data: GSS (1972-2016)") +
theme(legend.position = c(0.8, 0.25)) +
scale_y_continuous(limits = c(0,6), breaks = c(0,1,2,3,4,5,6), labels = c("Strong Democrat", "Not Strong Democrat", "Ind., near Dem.", "Independent", "Ind., near Rep.", "Not Strong Republican", "Strong Republican")) +
theme(legend.title=element_blank()) +
ggsave("D://pid_men_gss_long_together.png")
## Waffle ####
parts <- c(`White Evangelical Women w/College Degrees `= 3 , `White Not Evangelical Women w/College Degrees `= 14, `White Evangelical Men w/College Degrees `= 3 , `White Not Evangelical Men w/College Degrees `= 14, `Rest of the Electorate` = 166)
ev <- waffle(parts, legend_pos = "bottom", rows = 5) +
scale_fill_manual(values = c('White Evangelical Women w/College Degrees ' = "darkorchid", 'White Not Evangelical Women w/College Degrees ' = "dodgerblue3", 'White Evangelical Men w/College Degrees ' = "forestgreen", 'White Not Evangelical Men w/College Degrees ' = "firebrick1", 'Rest of the Electorate' = "azure3")) +
theme(text=element_text(size=84, family="font")) + theme(legend.title=element_blank()) +
labs(title = "Relative Size of the White College Educated Population", caption = "Data: CCES 2016") +
theme(plot.title = element_text(family = "font", size = 120, vjust =2, face = "bold")) +
guides(fill=guide_legend(nrow=2,byrow=TRUE)) +
theme(plot.margin=unit(c(2,1,2,1),"cm"))
ggsave(file="D://waffles_wmn_men.png", type = "cairo-png", width = 18, height = 12, ev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment