Last active
June 10, 2019 14:34
-
-
Save ryanburge/79529ce79d103e95347b3d51ab52e6ee to your computer and use it in GitHub Desktop.
Polarized Abortion
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 %>% | |
mutate(any = car::recode(abany, "1=1; 2=0; else = NA")) %>% | |
mutate(pid2 = car::recode(partyid, "0:2 = 'Democrat'; 4:6 = 'Republican'; else = NA")) %>% | |
group_by(year, pid2) %>% | |
mean_ci(any) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x = year, y = mean, group = pid2, color = pid2)) + | |
geom_point() + | |
geom_line() + | |
geom_ribbon(aes(ymin = lower, ymax = upper, color = pid2, fill = pid2), alpha = .2) + | |
theme_gg("Abel") + | |
theme(plot.title = element_text(size = 15)) + | |
scale_y_continuous(labels = percent) + | |
scale_fill_manual(values = c("dodgerblue3", "firebrick3")) + | |
scale_color_manual(values = c("dodgerblue3", "firebrick3")) + | |
annotate("text", x=2004, y = .55, label = "Democrats", size = 4, family = "font") + | |
annotate("text", x=2003.8, y = .37, label = "Republicans", size = 4, family = "font") + | |
labs(x = "Year", y = "Support Abortion For Any Reason", title = "Democrats Have Become More Accepting of Abortion Rights", caption = "@ryanburge\nData: GSS 1977-2018") + | |
ggsave("E://abort_gss_long_pid2.png", type = "cairo-png") | |
ab_fun <- function(df, var, name){ | |
var <- enquo(var) | |
gss %>% | |
mutate(any = car::recode(!! var, "1=1; 2=0; else = NA")) %>% | |
mutate(pid2 = car::recode(partyid, "0:2 = 'Democrat'; 4:6 = 'Republican'; else = NA")) %>% | |
group_by(year, pid2) %>% | |
mean_ci(any) %>% | |
na.omit() %>% | |
mutate(type = name) | |
} | |
qqq1 <- gss %>% ab_fun(abnomore, "Wants No More Kids") | |
qqq2 <- gss %>% ab_fun(abdefect, "Serious Defect") | |
qqq3 <- gss %>% ab_fun(abhlth, "Mother's Health") | |
qqq4 <- gss %>% ab_fun(abpoor, "Can't Afford More") | |
qqq5 <- gss %>% ab_fun(abrape, "Result of Rape") | |
qqq6 <- gss %>% ab_fun(absingle, "Not Married") | |
graph <- bind_df("qqq") | |
graph %>% | |
ggplot(., aes(x = year, y = mean, group = pid2, color = pid2)) + | |
geom_point() + | |
geom_line() + | |
geom_ribbon(aes(ymin = lower, ymax = upper, color = pid2, fill = pid2), alpha = .05) + | |
theme_gg("Abel") + | |
facet_wrap(~ type, ncol =3) + | |
scale_y_continuous(labels = percent) + | |
scale_fill_manual(values = c("dodgerblue3", "firebrick3")) + | |
scale_color_manual(values = c("dodgerblue3", "firebrick3")) + | |
theme(panel.spacing = unit(1, "lines")) + | |
scale_x_continuous(breaks = c(1980, 2000, 2020)) + | |
# theme(legend.position = "bottom") + | |
labs(x = "Year", y = "Support Abortion", title = "The Abortion Story is Much More Complicated", caption = "@ryanburge\nData: GSS 1977-2018") + | |
ggsave("E://abort_gss_long_pid2_six.png", type = "cairo-png") | |
graph %>% | |
filter(year == 1977 | year == 2018) %>% | |
ggplot(., aes(x = type, y = mean, fill = factor(year))) + | |
geom_col(color = "black", position = "dodge") + | |
facet_wrap(~ pid2, ncol = 1) + | |
theme_gg("Abel") + | |
theme(legend.position = "bottom") + | |
scale_fill_manual(values = c("#2B3252", "#EF5455")) + | |
scale_y_continuous(labels = percent) + | |
geom_text(aes(y = .2, label = paste0(mean*100, '%')), position = position_dodge(width = .9), size = 4, family = "font", color = "white") + | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9)) + | |
labs(x = "", y = "", title = "Support for Abortion by Party and Scenario", caption = "@ryanburge\nData: GSS 1977 + 2018") + | |
ggsave("E://abort_bars_gss.png", type = "cairo-png", width = 8) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment