Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created April 13, 2024 17:31
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/0400daa0eaae07665855f2dd19deea1c to your computer and use it in GitHub Desktop.
Save ryanburge/0400daa0eaae07665855f2dd19deea1c to your computer and use it in GitHub Desktop.
Catholic Weekly Attendance
over <- gss %>%
filter(year == 1982 | year == 1987) %>%
filter(reltrad == 1 | reltrad == 2 | reltrad == 3 | reltrad == 4) %>%
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1,
attend <= 5 ~ 0)) %>%
group_by(year, reltrad) %>%
mean_ci(att, wt = oversamp)
## This is the weight for the rest of the sample ####
wtss <- gss %>%
filter(year <= 2018) %>%
filter(reltrad == 1 | reltrad == 2 | reltrad == 3 | reltrad == 4) %>%
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1,
attend <= 5 ~ 0)) %>%
group_by(year, reltrad) %>%
mean_ci(att, wt = wtssall)
##Removing the two years that used the overweight ####
wtss <- wtss %>%
filter(year != 1982) %>%
filter(year != 1987)
last <- gss %>%
filter(year == 2021) %>%
filter(reltrad == 1 | reltrad == 2 | reltrad == 3 | reltrad == 4) %>%
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1,
attend <= 5 ~ 0)) %>%
group_by(year, reltrad) %>%
mean_ci(att, wt = wtssps) %>%
mutate(year = 2021)
## Bind them both together ####
graph <- bind_rows(over, wtss, last)
graph <- graph %>%
gss_reltrad(reltrad)
graph %>%
ggplot(., aes(x = year, y = mean, color = reltrad, group = reltrad)) +
geom_point(stroke = .5, shape = 21, alpha = .45) +
geom_labelsmooth(aes(label = reltrad), method = "lm", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size =6, linewidth = 1, boxlinewidth = 0.3, hjust = .65) +
y_pct() +
scale_color_manual(values = c(met.brewer("Johnson", 4))) +
theme_rb() +
labs(x = "Year", y = "", title = "Share Attending Services Nearly Every Week or More", caption = "@ryanburge\nData: General Social Survey, 1972-2021")
save("wk_att_reltrad.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment