Created
October 9, 2025 19:56
-
-
Save acbass49/2627370d3375855a29d4e696ecf0d619 to your computer and use it in GitHub Desktop.
20 Missionary Bump
This file contains hidden or 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
| library(tidyverse) | |
| library(binom) | |
| library(haven) | |
| library(car) | |
| library(ggtext) | |
| library(sjlabelled) | |
| # Load the dataset | |
| data <- readRDS("./data/CES/cumulative_2006-2024.rds") | |
| data$relig_church_rc <- car::recode(as.numeric(data$relig_church),"1:2 = 'Weekly or More'; 3 = 'Monthly'; 4:5 = 'A few times a year/Seldom'; 6 = 'Never'") | |
| data$relig_church_rc <- factor(data$relig_church_rc, | |
| levels = c("Weekly or More", "Monthly", "A few times a year/Seldom", "Never")) | |
| data$relig_church_rc2 <- car::recode(as.numeric(data$relig_church),"1:2 = 'Weekly or More'; 3:4 = 'Monthly/A few times a year'; 5:6 = 'Seldom/Never'") | |
| data$relig_church_rc2 <- factor(data$relig_church_rc2, | |
| levels = c("Weekly or More", "Monthly/A few times a year", "Seldom/Never")) | |
| data$year_4 <- car::recode(as.numeric(data$year), "2008:2012 = '2008-12'; 2013:2016 = '2013-16'; 2017:2020 = '2017-20'; 2021:2024 = '2021-24'") | |
| data$year_4 <- factor(data$year_4, | |
| levels = c("2008-12", "2013-16", "2017-20", "2021-24")) | |
| data$year_2 <- car::recode(as.numeric(data$year), "2007:2008 = '2007-08'; 2009:2010 = '2009-10'; 2011:2012 = '2011-12'; 2013:2014 = '2013-14'; 2015:2016 = '2015-16'; 2017:2018 = '2017-18'; 2019:2020 = '2019-20'; 2021:2022 = '2021-22'; 2023:2024 = '2023-24'") | |
| data$year_2 <- factor(data$year_2, | |
| levels = c("2007-08", "2009-10", "2011-12", "2013-14", "2015-16", "2017-18", "2019-20", "2021-22", "2023-24")) | |
| # prayer was not in the cumulative file, so I need to merge it in | |
| # I went through each year and added the prayer variable manually. | |
| data <- data |> | |
| mutate(id = paste0(year, "X", case_id)) |> | |
| left_join(read.csv("./data/CES/prayer.csv"), by = "id") |> | |
| mutate(year = year.x) | |
| data <- data |> | |
| mutate( | |
| prayer_rc = case_when( | |
| prayer == 1 ~ "Several Times a Day", | |
| prayer %in% 2:7 ~ "Less Than Several Times a Day", | |
| TRUE ~ NA_character_ | |
| ), | |
| prayer_rc2 = case_when( | |
| prayer %in% 1:2 ~ "Daily or More", | |
| prayer %in% 3:7 ~ "Less Than Several Times a Day", | |
| TRUE ~ NA_character_ | |
| ) | |
| ) | |
| data$devout <- dplyr::case_when( | |
| data$prayer_rc == "Several Times a Day" & | |
| data$relig_imp == "Very Important" & | |
| data$relig_church_rc == "Weekly or More" ~ 1, | |
| TRUE ~ 0 | |
| ) | |
| # abortion was not in the cumulative file, so I need to merge it in | |
| # I went through each year and added the abortion variable manually. | |
| plot <- data |> | |
| filter(religion == 3) |> | |
| filter(age<=80) |> | |
| group_by(age) |> | |
| count(devout, wt = weight) |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(devout == 1) |> | |
| ggplot(aes(x = age, y = prop, group = 1)) + | |
| geom_point( | |
| size = 1, | |
| stroke = 1.5, | |
| color = "grey", | |
| ) + | |
| geom_smooth(se = FALSE, color = "goldenrod") + | |
| #geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.2, color = "#FF8C00") + | |
| geom_text(aes(label = scales::percent(prop, accuracy = 1)), size = 1, family = "Cairo", fontface = "bold", color = "black") + | |
| labs( | |
| title = "<span style='color:goldenrod'>Latter-day Saint</span> Missionary Devotion Bump Visualized", | |
| subtitle = "Devout defined as praying several times a day,\nreligion very important,\nand attending church weekly or more", | |
| x = "Age", | |
| y = "Proportion", | |
| caption = "@mormon_metrics\nData: Cooperative Election Study (CES) 2008-24. N=9,189 LDS" | |
| ) + | |
| theme_minimal() + | |
| scale_y_continuous(labels = scales::percent_format(accuracy = 1), limits = c(0,0.8) , breaks = seq(0, 0.8, by = 0.1)) + | |
| scale_x_continuous(limits = c(18,80) , breaks = seq(20, 80, by = 5)) + | |
| theme( | |
| axis.ticks = element_blank(), | |
| axis.title = element_text(size = 14), | |
| axis.text.y = element_text(size = 10), | |
| axis.text.x = element_text(size = 10, margin = margin(t = -5)), | |
| plot.background = element_rect(fill = "grey95"), # Change entire plot background color here | |
| panel.background = element_blank(), | |
| text = element_text(face = "bold", family = "Cairo"), | |
| plot.title = ggtext::element_markdown(size = 15, face = "bold"), | |
| plot.subtitle = element_text(size = 11), | |
| plot.title.position = "plot", | |
| plot.subtitle.position = "plot", | |
| legend.title = element_blank(), | |
| legend.background = element_blank(), | |
| legend.box.background = element_blank(), | |
| legend.key = element_blank(), | |
| panel.grid = element_blank(), | |
| legend.position = "none", | |
| panel.grid.major.y = element_line(color = "lightgrey", linetype = 'solid'), | |
| plot.caption = element_text(size = 8,family = "Cairo") | |
| ) | |
| ggsave("./images/20_missionary_bump_1.png", plot, width = 1500, height = 1500, units = "px", dpi = 300) | |
| # Overall US Christians | |
| data |> | |
| filter(religion %in% c(1,2,4)) |> | |
| filter(age<=80) |> | |
| nrow() | |
| plot <- data |> | |
| filter(religion %in% c(1,2,4)) |> | |
| filter(age<=80) |> | |
| group_by(age) |> | |
| count(devout, wt = weight) |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(devout == 1) |> | |
| ggplot(aes(x = age, y = prop, group = 1)) + | |
| geom_point( | |
| size = 1, | |
| stroke = 1.5, | |
| color = "grey", | |
| ) + | |
| geom_smooth(se = FALSE, color = "dodgerblue") + | |
| #geom_errorbar(aes(ymin = lower, ymax = upper), width = 0.2, color = "#FF8C00") + | |
| geom_text(aes(label = scales::percent(prop, accuracy = 1)), size = 1, family = "Cairo", fontface = "bold", color = "black") + | |
| labs( | |
| title = "<span style='color:dodgerblue'>US Christians</span> Increase In Devotion With Age", | |
| subtitle = "Devout defined as praying several times a day,\nreligion very important,\nand attending church weekly or more", | |
| x = "Age", | |
| y = "Proportion", | |
| caption = "@mormon_metrics\nData: Cooperative Election Study (CES) 2008-24. N=369,310 US Christians" | |
| ) + | |
| theme_minimal() + | |
| scale_y_continuous(labels = scales::percent_format(accuracy = 1), limits = c(0,0.8) , breaks = seq(0, 0.8, by = 0.1)) + | |
| scale_x_continuous(limits = c(18,80) , breaks = seq(20, 80, by = 5)) + | |
| theme( | |
| axis.ticks = element_blank(), | |
| axis.title = element_text(size = 14), | |
| axis.text.y = element_text(size = 10), | |
| axis.text.x = element_text(size = 10, margin = margin(t = -5)), | |
| plot.background = element_rect(fill = "grey95"), # Change entire plot background color here | |
| panel.background = element_blank(), | |
| text = element_text(face = "bold", family = "Cairo"), | |
| plot.title = ggtext::element_markdown(size = 15, face = "bold"), | |
| plot.subtitle = element_text(size = 11), | |
| plot.title.position = "plot", | |
| plot.subtitle.position = "plot", | |
| legend.title = element_blank(), | |
| legend.background = element_blank(), | |
| legend.box.background = element_blank(), | |
| legend.key = element_blank(), | |
| panel.grid = element_blank(), | |
| legend.position = "none", | |
| panel.grid.major.y = element_line(color = "lightgrey", linetype = 'solid'), | |
| plot.caption = element_text(size = 8,family = "Cairo") | |
| ) | |
| ggsave("./images/20_missionary_bump_2.png", plot, width = 1500, height = 1500, units = "px", dpi = 300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment