Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
gg <- gss %>%
filter(race == 1) %>%
mutate(years = frcode(year >= 1985 & year <= 1990 ~ "1985-1990",
year >= 1991 & year <= 1995 ~ "1991-1995",
year >= 1996 & year <= 2000 ~ "1996-2000",
year >= 2001 & year <= 2005 ~ "2001-2005",
year >= 2006 & year <= 2010 ~ "2006-2010",
year >= 2011 & year <= 2015 ~ "2011-2015",
year >= 2016 & year <= 2020 ~ "2016-2018")) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(rel = frcode(reltrad == 1 ~ "Evangelical",
reltrad == 2 | reltrad == 3 | reltrad == 4 ~ "Other Christian",
reltrad == 5 | reltrad == 6 ~ "Other Faith",
reltrad == 7 ~ "No Religion")) %>%
filter(denom16 == 14) %>%
group_by(gender, years) %>%
ct(rel, wt = wtssall, show_na = FALSE)
gg %>%
filter(years != "NA") %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(rel))) +
geom_col(color = "black") +
coord_flip() +
facet_grid(years ~ gender, switch = "y") +
scale_fill_d3() +
theme_rb() +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle = 0)) +
guides(fill = guide_legend(reverse=T, nrow = 1)) +
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 >.08, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Where Do People Raised Southern Baptist End Up?", subtitle = "", caption = "@ryanburge\nData: GSS 1985-2018") +
ggsave("E://genders_sbc_reltrad.png", width = 9, height = 4)
gg <- gss %>%
filter(denom16 == 14) %>%
mutate(years = frcode(year >= 1985 & year <= 1990 ~ "'85-\n'90",
year >= 1991 & year <= 1995 ~ "'91-\n'95",
year >= 1996 & year <= 2000 ~ "'96-\n'00",
year >= 2001 & year <= 2005 ~ "'01-\n'05",
year >= 2006 & year <= 2010 ~ "'06-\n'10",
year >= 2011 & year <= 2015 ~ "'11-\n'15",
year >= 2016 & year <= 2020 ~ "'16-\n'18")) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(sbc = case_when(denom == 14 ~ 1,
TRUE ~ 0)) %>%
group_by(gender, years) %>%
mean_ci(sbc, wt = wtssall, ci = .84) %>%
mutate(type = "Born SBC - Stayed SBC") %>%
na.omit()
gg1 <- gss %>%
filter(denom16 == 22) %>%
mutate(years = frcode(year >= 1985 & year <= 1990 ~ "'85-\n'90",
year >= 1991 & year <= 1995 ~ "'91-\n'95",
year >= 1996 & year <= 2000 ~ "'96-\n'00",
year >= 2001 & year <= 2005 ~ "'01-\n'05",
year >= 2006 & year <= 2010 ~ "'06-\n'10",
year >= 2011 & year <= 2015 ~ "'11-\n'15",
year >= 2016 & year <= 2020 ~ "'16-\n'18")) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(sbc = case_when(denom == 22 ~ 1,
TRUE ~ 0)) %>%
group_by(gender, years) %>%
mean_ci(sbc, wt = wtssall, ci = .84) %>%
mutate(type = "Born UMC - Stayed UMC") %>%
na.omit()
gg2 <- gss %>%
filter(relig16 == 2) %>%
mutate(years = frcode(year >= 1985 & year <= 1990 ~ "'85-\n'90",
year >= 1991 & year <= 1995 ~ "'91-\n'95",
year >= 1996 & year <= 2000 ~ "'96-\n'00",
year >= 2001 & year <= 2005 ~ "'01-\n'05",
year >= 2006 & year <= 2010 ~ "'06-\n'10",
year >= 2011 & year <= 2015 ~ "'11-\n'15",
year >= 2016 & year <= 2020 ~ "'16-\n'18")) %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(sbc = case_when(relig == 2 ~ 1,
TRUE ~ 0)) %>%
group_by(gender, years) %>%
mean_ci(sbc, wt = wtssall, ci = .84) %>%
mutate(type = "Born Catholic - Stayed Catholic") %>%
na.omit()
graph <- bind_rows(gg, gg1, gg2)
graph %>%
ggplot(., aes(x = years, y = mean, fill = gender)) +
geom_col(color = "black", position = "dodge") +
facet_wrap(~ type) +
error_bar() +
y_pct() +
theme_rb(legend = TRUE) +
scale_fill_npg() +
labs(x = "", y= "", title = "Denominational Retention Rates by Gender", caption = "@ryanburge\nData: CCES 1985-2018") +
ggsave("E://retention_by_gender.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment