Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created July 23, 2025 13:55
Show Gist options
  • Select an option

  • Save ryanburge/5c18304fbc9464e1a40cd81ffebd5eb3 to your computer and use it in GitHub Desktop.

Select an option

Save ryanburge/5c18304fbc9464e1a40cd81ffebd5eb3 to your computer and use it in GitHub Desktop.
library(fst)
library(socsci)
library(car)
library(paletteer)
library(MetBrewer)
library(geomtextpath)
library(MoMAColors)
library(janitor)
source("C://Users/ryanb/OneDrive - Eastern Illinois University/Documents/mm/mm/theme.R")
nn <- read_csv("E://data/meaning_clusters.csv")
mean <- read_csv("E://data/meaning.csv") %>% clean_names()
ff <- read_csv("E://data/meaning_follow.csv")
source("C://Users/ryanb/OneDrive - Eastern Illinois University/Documents/mm/rename.R")
mean <- mean %>% mutate(cl = relig)
save <- function(name, wd, ht){
dir <- "E://graphs25/"
if(missing(wd) && missing(ht)){
ggsave(paste0(dir, name), width = 9, height = 6, bg = "white")
}else if(missing(wd)) {
ggsave(paste0(dir, name), width = 9, height = ht, bg = "white")
} else if(missing(ht)) {
ggsave(paste0(dir, name), width = wd, height = 6, bg = "white")
} else{
ggsave(paste0(dir, name), width = wd, height = ht, bg = "white")
}
}
## rename ####
mean <- mean %>%
rename(relig = q94) %>%
rename(birthyr = q505) %>%
rename(gender = q4) %>%
rename(race = q6) %>%
rename(hisp = q506) %>%
rename(relig16 = q502) %>%
rename(state = q28) %>%
rename(most_rel_age = q55_1) %>%
rename(most_rel_score = q89_1) %>%
rename(now_rel_score = q89_2) %>%
rename(most_rel_behave = q90_1) %>%
rename(now_rel_behave = q90_2) %>%
rename(attend = q70) %>%
rename(prayer = q71) %>%
rename(religimp = q72) %>%
rename(spiritimp = q138) %>%
rename(maattend = q129) %>%
rename(paattend = q130) %>%
rename(marel = q131) %>%
rename(parel = q132) %>%
rename(ev_now = q125) %>%
rename(ev_ever = q74) %>%
rename(ev_ma = q127) %>%
rename(ev_pa = q128) %>%
rename(life_sat = q250_1) %>%
rename(mtf_1 = q68_1) %>%
rename(mtf_2 = q68_2) %>%
rename(mtf_3 = q68_3) %>%
rename(mtf_4 = q68_4) %>%
rename(mtf_5 = q68_5) %>%
rename(mtf_6 = q68_6) %>%
rename(mtf_7 = q68_7) %>%
rename(mtf_8 = q68_8) %>%
rename(mtf_9 = q68_9) %>%
rename(mtf_10 = q68_10) %>%
rename(mtf_11 = q68_11) %>%
rename(mtf_12 = q68_12) %>%
rename(mtf_13 = q68_13) %>%
rename(mtf_14 = q68_14) %>%
rename(sec_aff1 = q53_1) %>%
rename(sec_aff2 = q53_2) %>%
rename(sec_aff3 = q53_3) %>%
rename(sec_aff4 = q53_4) %>%
rename(sec_aff5 = q53_5) %>%
rename(sec_reject1 = q54_1) %>%
rename(sec_reject2 = q54_2) %>%
rename(sec_reject3 = q54_3) %>%
rename(sp_person = q136) %>%
rename(rel_person = q137) %>%
rename(rel_pur1 = q46_1) %>%
rename(rel_pur2 = q46_2) %>%
rename(rel_pur3 = q46_3) %>%
rename(sp_pur1 = q47_1) %>%
rename(sp_pur2 = q47_2) %>%
rename(sp_pur3 = q47_3) %>%
rename(after1 = q48_1) %>%
rename(after2 = q48_2) %>%
rename(after3 = q48_3) %>%
rename(after4 = q48_4) %>%
rename(after5 = q48_5) %>%
rename(after6 = q48_6) %>%
rename(justice1 = q49_1) %>%
rename(justice2 = q49_2) %>%
rename(justice3 = q49_3) %>%
rename(justice4 = q49_4) %>%
rename(justice5 = q49_5) %>%
rename(s_act = q50) %>%
rename(rank_health = q51_1) %>%
rename(rank_mental = q51_2) %>%
rename(rank_emotion = q51_3) %>%
rename(rank_spirit = q51_4) %>%
rename(rank_social = q51_5) %>%
rename(rank_intell = q51_6) %>%
rename(rank_money = q51_7) %>%
rename(spirit1 = q52_1) %>%
rename(spirit2 = q52_2) %>%
rename(spirit3 = q52_3) %>%
rename(spirit4 = q52_4) %>%
rename(spirit5 = q52_5) %>%
rename(sp_item = q139) %>%
rename(leave_rel = q126) %>%
rename(per_trust = q41) %>%
rename(tr_comp = q42_1) %>%
rename(tr_relig = q42_2) %>%
rename(tr_educ = q42_3) %>%
rename(tr_pres = q42_4) %>%
rename(tr_labor = q42_5) %>%
rename(tr_media = q42_6) %>%
rename(tr_medicine = q42_7) %>%
rename(tr_tech = q42_8) %>%
rename(tr_scotus = q42_9) %>%
rename(tr_science = q42_10) %>%
rename(tr_congress = q42_11) %>%
rename(tr_mili = q42_12) %>%
rename(tr_banks = q42_13) %>%
rename(polpart = q43) %>%
rename(some1 = q44_1) %>%
rename(some2 = q44_2) %>%
rename(some3 = q44_3) %>%
rename(some4 = q44_4) %>%
rename(some5 = q44_5) %>%
rename(some6 = q44_6) %>%
rename(some7 = q44_7) %>%
rename(some8 = q44_8) %>%
rename(some9 = q44_9) %>%
rename(some10 = q44_10) %>%
rename(some11 = q44_11) %>%
rename(some12 = q44_12) %>%
rename(some13 = q44_13) %>%
rename(some14 = q44_14) %>%
rename(some15 = q44_15) %>%
rename(some16 = q44_16) %>%
rename(some17 = q44_17) %>%
rename(some18 = q44_18) %>%
rename(some19 = q44_19) %>%
rename(some20 = q44_20) %>%
rename(some21 = q44_21) %>%
rename(embryo1 = q82_1) %>%
rename(embryo2 = q82_2) %>%
rename(embryo3 = q82_3) %>%
rename(soul1 = q83_1) %>%
rename(soul2 = q83_2) %>%
rename(soul3 = q83_3) %>%
rename(soul4 = q83_4) %>%
rename(soul5 = q83_5) %>%
rename(soul6 = q83_6) %>%
rename(read_scrip = q84) %>%
rename(relorient1 = q85_1) %>%
rename(relorient2 = q85_2) %>%
rename(relorient3 = q85_3) %>%
rename(relorient4 = q85_4) %>%
rename(relknow1 = q86_1) %>%
rename(relknow2 = q86_2) %>%
rename(relknow3 = q86_3) %>%
rename(relknow4 = q86_4) %>%
rename(relknow5 = q86_5) %>%
rename(relknow6 = q86_6) %>%
rename(relknow7 = q86_7) %>%
rename(relknow8 = q86_8) %>%
rename(relknow9 = q86_9) %>%
rename(relknow10 = q86_10) %>%
rename(relbad1 = q87_1) %>%
rename(relbad2 = q87_2) %>%
rename(relbad3 = q87_3) %>%
rename(relbad4 = q87_4) %>%
rename(relbad5 = q87_5) %>%
rename(relbad6 = q87_6) %>%
rename(b_after = q88_1) %>%
rename(b_heaven = q88_2) %>%
rename(b_hell = q88_3) %>%
rename(b_miracles = q88_4) %>%
rename(b_reincarn = q88_5) %>%
rename(b_nivrana = q88_6) %>%
rename(b_angels = q88_7) %>%
rename(b_ghosts = q88_8) %>%
rename(b_prayer = q88_9) %>%
rename(b_crystals = q88_10) %>%
rename(b_ancestor = q88_11) %>%
rename(gay_refuse = q78) %>%
rename(twogen = q150_1) %>%
rename(porn = q150_2) %>%
rename(cas_sex = q150_3) %>%
rename(hard_drugs = q150_4) %>%
rename(sex_work = q150_5) %>%
rename(imp_emotion = q118_1) %>%
rename(imp_spirit = q118_2) %>%
rename(imp_mood = q118_3) %>%
rename(take_time = q118_4) %>%
rename(dislike_more = q118_5) %>%
rename(pol_involve = q118_6) %>%
rename(tolerant = q118_7) %>%
rename(rel_discrim = q119_1) %>%
rename(burqa = q119_2) %>%
rename(mili_hat = q119_3) %>%
rename(pres_faith = q36_1) %>%
rename(pol_trust_faith = q36_2) %>%
rename(moral_foundation = q36_3) %>%
rename(rel_extreme = q36_4) %>%
rename(ath_pol = q36_5) %>%
rename(belief_god = q38) %>%
rename(school_prayer = q40_1) %>%
rename(school_med = q40_2) %>%
rename(school_pledge = q40_3) %>%
rename(school_grad = q40_4) %>%
rename(therm_ev = q77_1) %>%
rename(therm_lds = q77_2) %>%
rename(therm_jew = q77_3) %>%
rename(therm_muslim = q77_4) %>%
rename(therm_atheist = q77_5) %>%
rename(therm_trans = q77_6) %>%
rename(therm_lgb = q77_7) %>%
rename(therm_dems = q77_8) %>%
rename(therm_gop = q77_9) %>%
rename(therm_me = q77_10) %>%
rename(vote_reg = q32) %>%
rename(vote2020 = q33) %>%
rename(vote2024 = q142) %>%
rename(ideo7 = q76) %>%
rename(pid7 = q34) %>%
rename(media_consume = q35) %>%
rename(home_life = q26) %>%
rename(home_state = q29) %>%
rename(home_geo = q30) %>%
rename(now_geo = q31) %>%
rename(income = q16) %>%
rename(inc_change = q17) %>%
rename(inc_future = q18) %>%
rename(inc_kid = q19) %>%
rename(employ = q12) %>%
rename(hours_work = q13) %>%
rename(industry = q14) %>%
rename(military = q15) %>%
rename(marital = q7) %>%
rename(divorce = q124) %>%
rename(marry_faith = q135_1) %>%
rename(age_marry = q7_a) %>%
rename(bgender = q2) %>%
rename(trans = q3) %>%
rename(sexorient = q5) %>%
rename(parent = q8) %>%
rename(numkids = q9) %>%
rename(immstat = q11) %>%
rename(age_parent = q8_a) %>%
rename(educ = q20) %>%
rename(educpa = q21) %>%
rename(educma = q22) %>%
rename(rel_school = q23) %>%
rename(major = q20_a) %>%
rename(alcohol = q145_1) %>%
rename(nictone = q145_2) %>%
rename(weed = q145_3) %>%
rename(gummy = q145_4) %>%
rename(heroin = q145_5) %>%
rename(cocaine = q145_6) %>%
rename(lsd = q145_7) %>%
rename(twitter = q146_1) %>%
rename(facebook = q146_2) %>%
rename(tiktok = q146_3) %>%
rename(instagram = q146_4) %>%
rename(snapchat = q146_5) %>%
rename(youtube = q146_6) %>%
rename(linkedin = q146_7) %>%
rename(reddit = q146_8) %>%
rename(pinterest = q146_9) %>%
rename(threads = q146_10)
## analysis ####
two <- mean %>%
filter(group == "Religious") %>%
mutate(religimp = factor(religimp, levels = c(
"Not at all important",
"Not too important",
"Somewhat important",
"Very important"
))) %>%
mutate(spiritimp = factor(spiritimp, levels = c(
"Not at all important",
"Not too important",
"Somewhat important",
"Very important"
))) %>%
group_by(religimp) %>%
ct(spiritimp, show_na = FALSE)
tot <- two %>%
ungroup() %>%
summarise(sum = sum(n))
two %>%
mutate(pct = n/3282)
two <- nn %>%
mutate(religimp = factor(religimp, levels = c(
"Not at all important",
"Not too important",
"Somewhat important",
"Very important"
))) %>%
mutate(spiritimp = factor(spiritimp, levels = c(
"Not at all important",
"Not too important",
"Somewhat important",
"Very important"
))) %>%
group_by(cl, religimp) %>%
ct(spiritimp, show_na = FALSE)
tot <- two %>%
ungroup() %>%
group_by(cl) %>%
summarise(sum = sum(n))
two <- left_join(two, tot) %>%
mutate(pct = n/sum)
two <- two %>%
mutate(
religimp = str_replace_all(religimp, "important", "") %>%
str_trim() %>%
str_replace_all("Not at all", "Not\nat all"),
spiritimp = str_replace_all(spiritimp, "important", "") %>%
str_trim()) %>%
filter(cl != 'NA')
two <- two %>%
mutate(bins = frcode(pct < .1 ~ "a",
pct >= .10 & pct <= .20 ~ "b",
pct > .20 ~ "c"))
two <- two %>%
mutate(
religimp = factor(religimp, levels = c("Not\nat all", "Not too", "Somewhat", "Very")),
spiritimp = factor(spiritimp, levels = c("Not at all", "Not too", "Somewhat", "Very"))
)
heat <- two %>%
filter(cl == "SBNR" | cl == "NiNo" | cl == "Dones")
heat %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = religimp, y = spiritimp, fill = bins)) +
geom_tile(aes(fill = bins), color = "black") +
scale_fill_manual(values = c("#6BDD5D","#FFC20D", "#FF1C0D")) +
theme_mm() +
facet_wrap(~ cl, nrow = 2) +
geom_text(aes(x= religimp, y = spiritimp, label = paste0(lab*100, '%')), size = 11, family = "font") +
geom_text(aes(x= religimp, y = spiritimp, label = ifelse(bins == "c", paste0(lab*100, '%'), "")), size = 11, family = "font", color = 'white') +
theme(strip.text = element_text(size = 24)) +
labs(x= "Religious Importance", y = "Spiritual Importance", title = "Religious Importance and Spiritual Importance\nAmong the NiNos and SBNRs", caption = "@ryanburge + @jonestony\nData: Making Meaning Survey, 2024")
save("ninos_sbnr_sp_rel_heatmap_new2.png", wd = 9.25, ht = 9)
gg1 <- nn %>%
filter(cl == "Dones") %>%
mutate(attend = frcode(
attend == "More than once a week" ~ "Weekly+",
attend == "Once a week" ~ "Weekly",
attend == "Once or twice a month" ~ "Monthly",
attend == "A few times a year" ~ "Yearly",
attend == "Seldom" ~ "Seldom",
attend == "Never" ~ "Never"
)) %>%
mutate(attend = fct_rev(attend)) %>%
ct(attend) %>%
mutate(type = "Dones")
gg2 <- nn %>%
filter(cl == "NiNo" | cl == "SBNR" | cl == "Zealous") %>%
mutate(attend = frcode(
attend == "More than once a week" ~ "Weekly+",
attend == "Once a week" ~ "Weekly",
attend == "Once or twice a month" ~ "Monthly",
attend == "A few times a year" ~ "Yearly",
attend == "Seldom" ~ "Seldom",
attend == "Never" ~ "Never"
)) %>%
mutate(attend = fct_rev(attend)) %>%
ct(attend) %>%
mutate(type = "Other\nNones")
gg3 <- mean %>%
filter(relig == "Protestant" | relig == "Roman Catholic") %>%
mutate(type = relig) %>%
mutate(type = frcode(type == "Protestant" ~ "Prot.",
type == "Roman Catholic" ~ "Cath.")) %>%
mutate(attend = frcode(
attend == "More than once a week" ~ "Weekly+",
attend == "Once a week" ~ "Weekly",
attend == "Once or twice a month" ~ "Monthly",
attend == "A few times a year" ~ "Yearly",
attend == "Seldom" ~ "Seldom",
attend == "Never" ~ "Never"
)) %>%
mutate(attend = fct_rev(attend)) %>%
group_by(type) %>%
ct(attend, show_na = FALSE)
all <- bind_rows(gg1, gg2, gg3) %>%
mutate(type = factor(type, levels = c("Dones", "Other\nNones", "Prot.", "Cath.")))
all %>%
ggplot(., aes(x = type, y = pct, fill = type)) +
geom_col(color = 'black') +
facet_wrap(~ attend) +
theme_mm() +
y_pct() +
scale_fill_manual(
values = c(
"Dones" = "#ff4e0d", # vivid orange-red (same as "Never" in other charts)
"Other\nNones" = "#0a0b72", # deep navy (same as "Seldom" etc.)
"Prot." = "#860456", # strong maroon
"Cath." = "#09c4ff" # bright cyan (used in your "Yearly" tier)
),
na.translate = FALSE
) +
lab_bar(above = TRUE, pos = .05, sz = 7, type = pct) +
labs(x = "", y = "", title = "How Often Do You Attend a House of Worship?", caption = "@ryanburge + @jonestony\nData: Making Meaning Survey, 2024")
save("dones_attend_compare.png", ht = 9)
# Group 1: Dones
gg1 <- nn %>%
filter(cl == "Dones") %>%
mutate(prayer = frcode(
prayer == "Never" ~ "Never",
prayer %in% c("Seldom", "A few times a month") ~ "Occasionally",
prayer %in% c("Once a week", "A few times a week") ~ "Weekly",
prayer == "Once a day" ~ "Daily",
prayer == "Several times a day" ~ "Multiple per day"
)) %>%
ct(prayer, show_na = FALSE) %>%
mutate(type = "Dones")
# Group 2: Other Nones
gg2 <- nn %>%
filter(cl %in% c("NiNo", "SBNR", "Zealous")) %>%
mutate(prayer = frcode(
prayer == "Never" ~ "Never",
prayer %in% c("Seldom", "A few times a month") ~ "Occasionally",
prayer %in% c("Once a week", "A few times a week") ~ "Weekly",
prayer == "Once a day" ~ "Daily",
prayer == "Several times a day" ~ "Multiple per day"
)) %>%
ct(prayer, show_na = FALSE) %>%
mutate(type = "Other\nNones")
# Group 3: Protestants and Catholics
gg3 <- mean %>%
filter(relig %in% c("Protestant", "Roman Catholic")) %>%
mutate(type = frcode(
relig == "Protestant" ~ "Prot.",
relig == "Roman Catholic" ~ "Cath."
)) %>%
mutate(prayer = frcode(
prayer == "Never" ~ "Never",
prayer %in% c("Seldom", "A few times a month") ~ "Occasionally",
prayer %in% c("Once a week", "A few times a week") ~ "Weekly",
prayer == "Once a day" ~ "Daily",
prayer == "Several times a day" ~ "Multiple per day"
)) %>%
group_by(type) %>%
ct(prayer, show_na = FALSE)
# Combine and order types
all_prayer <- bind_rows(gg1, gg2, gg3) %>%
mutate(type = factor(type, levels = c("Dones", "Other\nNones", "Prot.", "Cath.")))
# Optional: define color scale (from previous usage)
fill_colors <- c(
"Dones" = "#ff4e0d",
"Other\nNones" = "#0a0b72",
"Prot." = "#860456",
"Cath." = "#09c4ff"
)
# Plot
all_prayer %>%
ggplot(aes(x = type, y = pct, fill = type)) +
geom_col(color = 'black') +
facet_wrap(~ prayer) +
scale_fill_manual(values = fill_colors) +
theme_mm() +
y_pct() +
lab_bar(above = TRUE, pos = .05, sz = 7, type = pct) +
labs(
x = "", y = "",
title = "How Often Do You Pray?",
caption = "@ryanburge + @jonestony\nData: Making Meaning Survey, 2024"
)
save("dones_prayer_compare.png", ht = 9)
gg1 <- nn %>%
filter(cl == "Dones") %>%
mutate(belief = frcode(
belief_god == "I don't believe in God and I have no doubts." ~ "Atheist (No Doubt)",
belief_god == "I don't know if there is a God and I don't believe there is any way to find out." ~ "Agnostic (No Way to Know)",
belief_god == "I don't believe in a personal God, but I do believe in a higher power of some kind." ~ "Higher Power",
belief_god == "While I have doubts, I feel that I do believe in God." ~ "Believe w/ Doubts",
belief_god == "I know God exists and I have no doubts about it." ~ "Believe (No Doubt)"
)) %>%
ct(belief) %>%
mutate(type = "Dones")
# Group 2: Other Nones
gg2 <- nn %>%
filter(cl %in% c("NiNo", "SBNR", "Zealous")) %>%
mutate(belief = frcode(
belief_god == "I don't believe in God and I have no doubts." ~ "Atheist (No Doubt)",
belief_god == "I don't know if there is a God and I don't believe there is any way to find out." ~ "Agnostic (No Way to Know)",
belief_god == "I don't believe in a personal God, but I do believe in a higher power of some kind." ~ "Higher Power",
belief_god == "While I have doubts, I feel that I do believe in God." ~ "Believe w/ Doubts",
belief_god == "I know God exists and I have no doubts about it." ~ "Believe (No Doubt)"
)) %>%
ct(belief, show_na = FALSE) %>%
mutate(type = "Other Nones")
# Group 3: Protestants and Catholics
gg3 <- mean %>%
filter(relig %in% c("Protestant", "Roman Catholic")) %>%
mutate(type = frcode(
relig == "Protestant" ~ "Protestant",
relig == "Roman Catholic" ~ "Catholic"
)) %>%
mutate(belief = frcode(
belief_god == "I don't believe in God and I have no doubts." ~ "Atheist (No Doubt)",
belief_god == "I don't know if there is a God and I don't believe there is any way to find out." ~ "Agnostic (No Way to Know)",
belief_god == "I don't believe in a personal God, but I do believe in a higher power of some kind." ~ "Higher Power",
belief_god == "While I have doubts, I feel that I do believe in God." ~ "Believe w/ Doubts",
belief_god == "I know God exists and I have no doubts about it." ~ "Believe (No Doubt)"
)) %>%
group_by(type) %>%
ct(belief, show_na = FALSE)
# Combine and order types
belief <- bind_rows(gg1, gg2, gg3) %>%
mutate(type = factor(type, levels = c("Dones", "Other Nones", "Protestant", "Catholic")))
belief %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(belief))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "left") +
theme_mm() +
theme(legend.position = "bottom") +
scale_fill_manual(
values = c(
"Atheist (No Doubt)" = "#ff4e0d", # vivid orange-red (used for "Never" etc.)
"Agnostic (No Way to Know)" = "#0a0b72", # deep navy
"Higher Power" = "#09c4ff", # bright cyan
"Believe w/ Doubts" = "#860456", # rich maroon
"Believe (No Doubt)" = "#918fe4" # lavender/light purple
),
na.translate = FALSE
) +
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 >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
# geom_text(aes(label = ifelse(age2 == "18-35", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") +
# geom_text(aes(label = ifelse(age2 == "36-44", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(legend.text = element_text(size = 10)) +
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) +
labs(
x = "", y = "",
title = "Which Statement Best Describes Your Belief in God?",
caption = "@ryanburge + @jonestony\nData: Making Meaning Survey, 2024"
)
save("belief_god_dones.png", wd = 10, ht = 5)
# Dones
gg1 <- nn %>%
mutate(age = 2024 - birthyr) %>%
mutate(age2 = frcode(
age >= 18 & age <= 35 ~ "18-35",
age >= 36 & age <= 44 ~ "36-44",
age >= 45 & age <= 54 ~ "45-54",
age >= 55 & age <= 64 ~ "55-64",
age >= 65 ~ "65+"
)) %>%
filter(cl == "Dones") %>%
ct(age2, show_na = FALSE) %>%
mutate(type = "Dones")
# Other Nones: NiNo, SBNR, Zealous
gg2 <- nn %>%
mutate(age = 2024 - birthyr) %>%
mutate(age2 = frcode(
age >= 18 & age <= 35 ~ "18-35",
age >= 36 & age <= 44 ~ "36-44",
age >= 45 & age <= 54 ~ "45-54",
age >= 55 & age <= 64 ~ "55-64",
age >= 65 ~ "65+"
)) %>%
filter(cl %in% c("NiNo", "SBNR", "Zealous")) %>%
ct(age2, show_na = FALSE) %>%
mutate(type = "Other Nones")
# Protestants and Catholics
gg3 <- mean %>%
mutate(age = 2024 - birthyr) %>%
mutate(age2 = frcode(
age >= 18 & age <= 35 ~ "18-35",
age >= 36 & age <= 44 ~ "36-44",
age >= 45 & age <= 54 ~ "45-54",
age >= 55 & age <= 64 ~ "55-64",
age >= 65 ~ "65+"
)) %>%
filter(relig %in% c("Protestant", "Roman Catholic")) %>%
mutate(type = frcode(
relig == "Protestant" ~ "Protestant",
relig == "Roman Catholic" ~ "Catholic"
)) %>%
group_by(type) %>%
ct(age2, show_na = FALSE)
# Combine and order types
all <- bind_rows(gg1, gg2, gg3) %>%
mutate(type = factor(type, levels = c("Dones", "Other Nones", "Protestant", "Catholic")))
# Plot or process as needed
all %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(age2))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "left") +
theme_mm() +
theme(legend.position = "bottom") +
scale_fill_manual(
values = c(
"18-35" = "#9fe1ff", # light blue
"36-44" = "#60b3ff", # mid blue
"45-54" = "#2980b9", # deeper blue
"55-64" = "#15507d", # dark blue
"65+" = "#0a0b72" # navy (used before for older categories)
),
na.translate = FALSE
) +
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 >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
geom_text(aes(label = ifelse(pct >.05 & age2 == "18-35", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
geom_text(aes(label = ifelse(pct >.05 & age2 == "36-44", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) +
labs(
x = "", y = "",
title = "Age Distribution of The Nones and Christians",
caption = "@ryanburge + @jonestony\nData: Making Meaning Survey, 2024"
)
save("age_dist_dones.png", wd = 10, ht = 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment