/ct_selection_untitled-32D56CBC.R Secret
Created
May 6, 2023 03:59
Star
You must be signed in to star a gist
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
over <- gss %>% | |
filter(year == 1982 | year == 1987) %>% | |
group_by(year) %>% | |
ct(reltrad, wt = oversamp) | |
## This is the weight for the rest of the sample #### | |
wtss <- gss %>% | |
filter(year <= 2018) %>% | |
group_by(year) %>% | |
ct(reltrad, wt = wtssall) | |
##Removing the two years that used the overweight #### | |
wtss <- wtss %>% | |
filter(year != 1982) %>% | |
filter(year != 1987) | |
last <- gss %>% | |
filter(year == 2021) %>% | |
ct(reltrad, wt = wtssps) %>% | |
mutate(year = 2021) | |
## Bind them both together #### | |
graph <- bind_rows(over, wtss, last) | |
graph <- graph %>% | |
mutate(reltrad = frcode(reltrad == 1 ~ "Evangelical", | |
reltrad == 2 ~ "Mainline", | |
reltrad == 3 ~ "Black Prot.", | |
reltrad == 4 ~ "Catholic", | |
reltrad == 5 ~ "Jewish", | |
reltrad == 6 ~ "Other Faith", | |
reltrad == 7 ~ "No Religion", | |
TRUE ~ "Unclassified")) | |
graph %>% | |
filter(reltrad == "Catholic") %>% | |
ggplot(., aes(x = year, y = pct)) + | |
geom_line() + | |
geom_point(stroke = 1, shape = 21, fill = "white") + | |
geom_smooth(se = FALSE, linetype = "twodash", color = "black") + | |
scale_y_continuous(labels = percent, limits = c(0, .29)) + | |
theme_rb() + | |
labs(x = "", y = "", title = "Share of Americans Who Identify as Catholic", caption = "@ryanburge\nData: General Social Survey, 1972-2021") | |
save("cath_gss21.png") | |
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") | |
over <- gss %>% | |
filter(year == 1982 | year == 1987) %>% | |
filter(reltrad == 4) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1, | |
attend <= 5 ~ 0)) %>% | |
group_by(year, reltrad, pid3) %>% | |
mean_ci(att, wt = oversamp) | |
## This is the weight for the rest of the sample #### | |
wtss <- gss %>% | |
filter(year <= 2018) %>% | |
filter(reltrad == 4) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1, | |
attend <= 5 ~ 0)) %>% | |
group_by(year, reltrad, pid3) %>% | |
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 == 4) %>% | |
mutate(pid7 = partyid + 1) %>% | |
cces_pid3(pid7) %>% | |
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1, | |
attend <= 5 ~ 0)) %>% | |
group_by(year, reltrad, pid3) %>% | |
mean_ci(att, wt = wtssps) %>% | |
mutate(year = 2021) | |
## Bind them both together #### | |
graph <- bind_rows(over, wtss, last) %>% filter(pid3 != "NA") | |
graph %>% | |
ggplot(., aes(x = year, y = mean, color = pid3, group = pid3)) + | |
geom_point(stroke = .5, shape = 21, alpha = .45) + | |
geom_labelsmooth(aes(label = pid3), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size =5, linewidth = 1, boxlinewidth = 0.3, hjust = .65) + | |
pid3_color() + | |
y_pct() + | |
theme_rb() + | |
labs(x = "Year", y = "", title = "Share of Catholics Attending Mass Nearly Every Week or More", caption = "@ryanburge\nData: General Social Survey, 1972-2021") | |
save("cath_pid3_attend.png") | |
ggg <- cces %>% | |
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022) %>% | |
cces_pid3(pid7) %>% | |
filter(race == 1 & religion == 2) %>% | |
mutate(att2 = frcode(pew_attendance == 6 | pew_attendance == 5 ~ "Never/Seldom", | |
pew_attendance == 1 | pew_attendance == 2 ~ "Weekly")) %>% | |
group_by(year, att2) %>% | |
ct(pid3, wt = weight, show_na = FALSE) %>% | |
filter(att2 != "NA") | |
ggg %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid3))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_grid(year ~ att2, switch = "y") + | |
pid3_fill(rev = TRUE) + | |
theme_rb(legend = TRUE) + | |
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(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 6, family = "font", color = "black") + | |
labs(x = "", y = "", title = "Partisanship of White Catholics by Church Attendance", subtitle = "", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022") | |
save("att_cath_pid3_ces2022.png", wd = 9, ht = 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment