Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created January 13, 2022 22:22
Show Gist options
  • Save ryanburge/9f2eb2b9fa36c1e651f86d6df7d4bd3e to your computer and use it in GitHub Desktop.
Save ryanburge/9f2eb2b9fa36c1e651f86d6df7d4bd3e to your computer and use it in GitHub Desktop.
aa <- cces %>%
mutate(ev = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
filter(year == 2010 | year == 2020) %>%
group_by(birthyr, year) %>%
mean_ci(ev, wt = weight, ci = .84)
aa <- aa %>%
mutate(cohorts = frcode(birthyr >= 1919 & birthyr <= 1928 ~ "1925-1929",
birthyr >= 1929 & birthyr <= 1938 ~ "1930-1934",
birthyr >= 1939 & birthyr <= 1948 ~ "1935-1939",
birthyr >= 1949 & birthyr <= 1958 ~ "1940-1944",
birthyr >= 1959 & birthyr <= 1968 ~ "1945-1949",
birthyr >= 1969 & birthyr <= 1978 ~ "1950-1954",
birthyr >= 1979 & birthyr <= 1988 ~ "1955-1959",
birthyr >= 1989 & birthyr <= 1998 ~ "1960-1964",
birthyr >= 1999 & birthyr <= 2002 ~ "1965-1969"))
aa %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = factor(year), y = mean, group = factor(birthyr), color = cohorts)) +
geom_point() +
geom_line() +
facet_wrap(~ birthyr) +
y_pct() +
geom_area(aes(fill=cohorts), alpha = .25) +
scale_color_tableau(palette = "Tableau 10") +
scale_fill_tableau(palette = "Tableau 10") +
geom_text(aes(y = lab + .09, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 4, family = "font", color = "black") +
theme_rb() +
labs(x = "Year", y = "", title = "Percent Who Self-Identify as Evangelical by Birth Year in 2010 vs 2020", caption = "@ryanburge\nData: CES 2010+2020") +
ggsave("E://birthyr_slopes_ev.png", type = "cairo-png", width = 12, height = 12)
# https://gist.github.com/9f2eb2b9fa36c1e651f86d6df7d4bd3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment