Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created May 13, 2025 13:46
Show Gist options
  • Select an option

  • Save ryanburge/7e8ccc4aa282782afb76b849b9fb2b6f to your computer and use it in GitHub Desktop.

Select an option

Save ryanburge/7e8ccc4aa282782afb76b849b9fb2b6f to your computer and use it in GitHub Desktop.
gg <- gss %>%
filter(year >= 2021) %>%
filter(reltrad <= 4) %>%
gss_reltrad6(reltrad) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(reltrad) %>%
ct(gd, wt = wtssnrps, show_na = FALSE)
gg %>%
ggplot(., aes(x = gd, y = pct, fill = gd)) +
geom_col(color = "black") +
facet_wrap(~ reltrad) +
coord_flip() +
theme_rb() +
y_pct() +
lab_bar(above = TRUE, pos = .055, sz = 5, type = pct) +
scale_fill_manual(values = c(
"Don't Believe" = "#2F4858",
"No Way to Find Out" = "#33658A",
"Some Higher Power" = "#86BBD8",
"Believe Sometimes" = "#F6AE2D",
"Believe But Doubts" = "#F26419",
"Believe No Doubts" = "#8AC926"
)) +
labs(x = "", y = "", title = "Belief in God Among Christian Groups", caption = "@ryanburge\nData: General Social Survey, 2021-2022")
save("gss_belief_xtn_22.png")
gg1 <- gss %>%
filter(year <= 2018) %>%
filter(reltrad <= 4) %>%
gss_reltrad6(reltrad) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year, reltrad) %>%
ct(gd, wt = wtssall, show_na = FALSE)
gg2 <- gss %>%
filter(year > 2018) %>%
filter(reltrad <= 4) %>%
gss_reltrad6(reltrad) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year, reltrad) %>%
ct(gd, wt = wtssnrps, show_na = FALSE)
both <- bind_rows(gg1, gg2) %>% filter(gd == "Believe No Doubts")
both %>%
ggplot(., aes(x = year, y = pct, color = reltrad, group = reltrad)) +
geom_point(stroke = 1, shape = 21) +
geom_labelsmooth(aes(label = reltrad), method = "loess", formula = y ~ x, family = "font", linewidth = 1, text_smoothing = 30, size = 8, linewidth = 1, boxlinewidth = 0.3) +
theme_rb() +
scale_color_manual(values = c(
"Evangelical" = "#1b9e77", # Teal green
"Mainline" = "#d95f02", # Burnt orange
"Black Prot." = "#7570b3", # Deep purple
"Catholic" = "#e7298a", # Magenta pink
"Other Faith" = "#66a61e" # Olive green (if needed)
)) +
scale_y_continuous(labels = percent) +
labs(x= "", y = "", title = "Share of Christians With a Certain Belief in God, 1988-2022", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("certain_belief_xtns_over_time.png")
gg1 <- gss %>%
filter(year <= 2018) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain Belief",
god <= 5 ~ "Less Certain")) %>%
gss_attend(attend) %>%
group_by(year, gd) %>%
ct(att, wt = wtssall, show_na = FALSE) %>%
na.omit()
gg2 <- gss %>%
filter(year > 2018) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain Belief",
god <= 5 ~ "Less Certain")) %>%
gss_attend(attend) %>%
group_by(year, gd) %>%
ct(att, wt = wtssnrps, show_na = FALSE) %>%
na.omit()
both <- bind_rows(gg1, gg2)
both %>%
ggplot(., aes(x = year, y = pct, color = att, group = att)) +
geom_point(stroke = .25, shape = 21, alpha = .5) +
geom_smooth(se = FALSE) +
facet_wrap(~ gd) +
theme_rb(legend = TRUE) +
y_pct() +
scale_color_manual(values = c(
"Never" = "#999999", # Medium gray
"Seldom" = "#377eb8", # Muted blue
"Yearly" = "#4daf4a", # Muted green
"Monthly" = "#984ea3", # Purple
"Weekly" = "#ff7f00" # Orange
)) +
theme(strip.text = element_text(size = 24)) +
theme(legend.text = element_text(size = 20)) +
labs(x = "Year", y = "", title = "Mass Attendance Among Catholics By Belief in God", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("gss_cath_att_belief22.png")
gg1 <- gss %>%
filter(year <= 2018) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain Belief",
god <= 5 ~ "Less Certain")) %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
group_by(year, gd) %>%
ct(pid3, wt = wtssall, show_na = FALSE) %>%
na.omit()
gg2 <- gss %>%
filter(year > 2018) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain Belief",
god <= 5 ~ "Less Certain")) %>%
mutate(pid7 = partyid + 1) %>%
cces_pid3(pid7) %>%
group_by(year, gd) %>%
ct(pid3, wt = wtssnrps, show_na = FALSE) %>%
na.omit()
both <- bind_rows(gg1, gg2)
both %>%
ggplot(., aes(x = year, y = pct, color = pid3, group = pid3)) +
geom_point(stroke = .25, shape = 21, alpha = .5) +
geom_smooth(se = FALSE) +
facet_wrap(~ gd) +
theme_rb(legend = TRUE) +
y_pct() +
pid3_color() +
theme(strip.text = element_text(size = 24)) +
theme(legend.text = element_text(size = 20)) +
labs(x = "Year", y = "", title = "Political Partisanship Among Catholics By Belief in God", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("gss_cath_pid3_belief22.png")
gg1 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(imm = case_when(immjobs == 1 | immjobs == 2 ~ 1,
immjobs <= 5 ~ 0)) %>%
group_by(gd) %>%
mean_ci(imm, wt = wtssnrps) %>%
mutate(type = "Immigrants Take\nAway Jobs")
gg2 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(ab = case_when(abany == 1 ~ 1,
abany == 2 ~ 0)) %>%
group_by(gd) %>%
mean_ci(ab, wt = wtssnrps) %>%
mutate(type = "Allow Abortion,\nAny Reason")
gg3 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(mar = case_when(marhomo == 1 | marhomo == 2 ~ 1,
marhomo <= 5 ~ 0)) %>%
group_by(gd) %>%
mean_ci(mar, wt = wtssnrps) %>%
mutate(type = "Permit Gay\nMarriage")
gg4 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(mar = case_when(homosex == 1 ~ 1,
homosex <= 5 ~ 0)) %>%
group_by(gd) %>%
mean_ci(mar, wt = wtssnrps) %>%
mutate(type = "Gay Sex\nAlways Wrong")
gg5 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(mar = case_when(cappun == 1 ~ 1,
cappun == 2 ~ 0)) %>%
group_by(gd) %>%
mean_ci(mar, wt = wtssnrps) %>%
mutate(type = "Captial Punishment\nfor Murder")
gg6 <- gss %>%
filter(year == 2022) %>%
filter(reltrad == 4) %>%
mutate(gd = frcode(god == 6 ~ "Certain\nBelief",
god <= 5 ~ "Less\nCertain")) %>%
mutate(hh = case_when(helpsick == 1 | helpsick == 2 ~ 1,
helpsick == 3 | helpsick == 4 | helpsick == 5 ~ 0)) %>%
group_by(gd) %>%
mean_ci(hh, wt = wtssnrps) %>%
mutate(type = "Govt. Should Help People\nPay for Health Care")
all <- bind_rows(gg1, gg2, gg3, gg4, gg5, gg6) %>% filter(gd != "NA")
all %>%
ggplot(., aes(x = gd, y = mean, fill = gd)) +
geom_col(color = "black") +
facet_wrap(~ type) +
theme_rb() +
scale_fill_manual(values = c(
"Certain\nBelief" = "#1b9e77", # Teal green
"Less\nCertain" = "#d95f02" # Burnt orange
)) +
scale_y_continuous(labels = percent, limits = c(0, 1)) +
theme(strip.text = element_text(size = 12)) +
lab_bar(above = TRUE, pos = .075, sz = 9, type = mean) +
labs(x = "", y = "", title = "Public Opinion Among Catholics by Belief in God", caption = "@ryanburge\nData: General Social Survey, 2022")
save("gss_cath_opinion_beliefs.png", wd = 5.75, ht = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment