Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Last active December 16, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/1ba09787e6d9e9c6b8882fd271d70e1d to your computer and use it in GitHub Desktop.
Save ryanburge/1ba09787e6d9e9c6b8882fd271d70e1d to your computer and use it in GitHub Desktop.
What Turned the Tide on Gay Marriage?
## Graph 1 ####
gg1 <- gss %>%
mutate(ab = car::recode(marhomo, "1:2= 1; 3:5=0; else = NA")) %>%
group_by(year) %>%
mean_ci(ab) %>%
na.omit() %>%
mutate(group = "Same Sex Marriage")
gg2 <- gss %>%
mutate(ab = car::recode(abany, "1=1;2=0; else = NA")) %>%
group_by(year) %>%
mean_ci(ab) %>%
na.omit() %>%
mutate(group = "Abortion - Any Reason")
gg3 <- gss %>%
mutate(ab = car::recode(pornlaw, "1=1; 2=0; else = NA")) %>%
group_by(year) %>%
mean_ci(ab) %>%
na.omit() %>%
mutate(group = "Porno Illegal")
graph <- bind_rows(gg1, gg2, gg3)
graph %>%
ggplot(., aes(x = year, y = mean, color = group, group = group)) +
geom_point(size=3, color="white") +
geom_point(size=2, shape=1) +
geom_point(size=1, shape=19) +
geom_smooth(se = FALSE, linetype = "twodash") +
scale_color_tableau() +
theme_gg("Abel") +
scale_x_continuous(breaks = c(1978, 1988, 1998, 2008, 2018)) +
y_pct() +
add_text(x = 1990, y = .17, word = "Favor Same\nSex Marriage", sz = 4) +
add_text(x = 1980, y = .48, word = "Make Porn Illegal\nfor All", sz = 4) +
add_text(x = 1982, y = .335, word = "Allow Abortion\nfor Any Reason", sz = 4) +
labs(x = "", y = "", title = "Support for Culture War Issues", caption = "@ryanburge\nData: GSS 1972-2018") +
ggsave("E://culture_wars.png", type = "cairo-png")
## Graph 2 ####
regg <- gss %>%
mutate(trad = frcode(evangelical == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 ~ "Catholic",
nofaith == 1 ~ "Nones")) %>%
mutate(ab = car::recode(marhomo, "1:2= 1; 3:5=0; else = NA")) %>%
mutate(male = car::recode(sex, "1=1; 2=0; else = NA")) %>%
mutate(yrs = as.factor(year)) %>%
mutate(age2 = car::recode(age, "18:35 =1; 36:44 = 2; 45:54 = 3; 55:64 = 4; 65:100 = 5"))
reg1 <- glm(ab ~ trad*age2*yrs + educ + male + attend, data = regg, family = "binomial")
gg2 <- interact_plot(reg1, pred= age2, modx = trad, mod2 = yrs, int.width = .76, interval = TRUE, mod2.labels = c("1988", "2004", "2006", "2008", "2010", "2012", "2014", "2016", "2018"))
gg2 +
scale_color_tableau() +
scale_fill_tableau() +
theme_gg("Abel") +
theme(legend.position = "bottom") +
y_pct() +
labs(x = "", y = "", title = "Support for Same Sex Marriage by Tradition and Age", caption = "@ryanburge\nData: GSS 1988-2018") +
scale_x_continuous(breaks = c(1,2,3,4,5), labels = c("18-\n35", "36-44", "45-54", "55-64", "65+")) +
ggsave("E://marhomo_interact.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment