Created
September 11, 2024 14:42
-
-
Save ryanburge/0a8211ea7df0c79b69cf3d099075388c to your computer and use it in GitHub Desktop.
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
| gg <- gss %>% | |
| mutate(miracles = frcode(miracles == 4 ~ "Definitely Not", | |
| miracles == 3 ~ "Probably Not", | |
| miracles == 2 ~ "Probably", | |
| miracles == 1 ~ "Definitely")) %>% | |
| group_by(year) %>% | |
| ct(miracles, wt = wtssall, show_na = FALSE) | |
| gg %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(., aes(x = 1, y = pct, fill = fct_rev(miracles))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ year, ncol =1, strip.position = "left") + | |
| theme_rb() + | |
| scale_fill_manual(values = c( "#033f63", "#28666e", "#7D3C98", "#5f2680")) + | |
| 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 >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
| theme(plot.title = element_text(size = 26)) + | |
| theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
| labs(x = "", y = "", title = "Do you believe in religious miracles?", caption = "@ryanburge + @religiondata\nData: General Social Survey, 1991-2018") | |
| save("believe_miracles_arda.png", wd = 9, ht = 4) | |
| gg <- gss %>% | |
| filter(reltrad != 7) %>% | |
| mutate(miracles = frcode(miracles == 4 ~ "Definitely Not", | |
| miracles == 3 ~ "Probably Not", | |
| miracles == 2 ~ "Probably", | |
| miracles == 1 ~ "Definitely")) %>% | |
| group_by(year) %>% | |
| ct(miracles, wt = wtssall, show_na = FALSE) | |
| gg %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(., aes(x = 1, y = pct, fill = fct_rev(miracles))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ year, ncol =1, strip.position = "left") + | |
| theme_rb() + | |
| scale_fill_manual(values = c( "#033f63", "#28666e", "#7D3C98", "#5f2680")) + | |
| 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 >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
| theme(plot.title = element_text(size = 22)) + | |
| theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
| labs(x = "", y = "", title = "Do you believe in religious miracles? - Excluding the Non-Religious", caption = "@ryanburge + @religiondata\nData: General Social Survey, 1991-2018") | |
| save("believe_miracles_arda_nones.png", wd = 9, ht = 4) | |
| gg <- gss %>% | |
| gss_reltrad6(reltrad) %>% | |
| mutate(def = case_when(miracles == 1 ~ 1, | |
| miracles <= 4 ~ 0)) %>% | |
| group_by(year, reltrad) %>% | |
| mean_ci(def, wt = wtssall, ci = .84) %>% | |
| na.omit() | |
| gg %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = fct_rev(reltrad), y = mean, fill = reltrad)) + | |
| geom_col(color = "black") + | |
| facet_wrap(~ year, ncol = 1) + | |
| theme_rb() + | |
| coord_flip() + | |
| geom_text(aes(y = mean + .04, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 5, family = "font") + | |
| scale_fill_manual(values = c("#28666e", "#5f2680", "#B5B682", "azure4", "#e1e1e1", "#033f63")) + | |
| y_pct() + | |
| theme(strip.text = element_text(size = 16)) + | |
| labs(x = "", y = "", title = "Share Saying they Definitely Believe in Religious Miracles", caption = "@ryanburge + @religiondata\nData: General Social Survey, 1991-2018") | |
| save("def_miracles_reltrad.png", ht = 8, wd = 6.5) | |
| one <- gss %>% | |
| filter(reltrad != 7) %>% | |
| mutate(educ = frcode(educ <= 12 ~ "HS or Less", | |
| educ >= 13 & educ <= 15 ~ "Some College", | |
| educ == 16 ~ "Bachelors", | |
| educ >= 17 ~ "Graduate School")) %>% | |
| mutate(def = case_when(miracles == 1 ~ 1, | |
| miracles <= 4 ~ 0)) %>% | |
| group_by(educ, year) %>% | |
| mean_ci(def, wt = wtssall, ci = .84) %>% | |
| na.omit() | |
| one %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = mean, fill = factor(year))) + | |
| geom_col(color = "black") + | |
| facet_wrap(~ educ) + | |
| theme_rb() + | |
| scale_fill_manual(values = c("#28666e", "#5f2680", "#B5B682", "azure4", "#033f63")) + | |
| error_bar() + | |
| y_pct() + | |
| geom_text(aes(y = .05, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") + | |
| geom_text(aes(y = .05, label = ifelse(year == "1991", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 8, family = "font", color = 'white') + | |
| geom_text(aes(y = .05, label = ifelse(year == "1998", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 8, family = "font", color = 'white') + | |
| labs(x = "", y = "", title = "Share Saying they Definitely Believe in Religious Miracles", caption = "@ryanburge + @religiondata\nData: General Social Survey, 1991-2018") | |
| save("def_miracles_educ.png", ht = 8, wd = 6.5) | |
| graph <- gss %>% | |
| mutate(birthyr = year - age) %>% | |
| mutate(decades = frcode(birthyr >= 1930 & birthyr <= 1939 ~ "1930s", | |
| birthyr >= 1940 & birthyr <= 1949 ~ "1940s", | |
| birthyr >= 1950 & birthyr <= 1959 ~ "1950s", | |
| birthyr >= 1960 & birthyr <= 1969 ~ "1960s", | |
| birthyr >= 1970 & birthyr <= 1979 ~ "1970s", | |
| birthyr >= 1980 & birthyr <= 1989 ~ "1980s")) %>% | |
| mutate(def = case_when(miracles == 1 ~ 1, | |
| miracles <= 4 ~ 0)) %>% | |
| group_by(decades, year) %>% | |
| mean_ci(def, wt = wtssall, ci = .84) %>% | |
| na.omit() %>% filter(n > 75) | |
| graph %>% | |
| mutate(lab = round(mean, 2)) %>% | |
| ggplot(., aes(x = factor(year), y = mean, fill = factor(decades))) + | |
| geom_col(color = "black") + | |
| facet_wrap(~ decades) + | |
| theme_rb() + | |
| y_pct() + | |
| error_bar() + | |
| theme(plot.title = element_text(size = 15)) + | |
| geom_text(aes(y = .05, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 6.5, family = "font") + | |
| geom_text(aes(y = .05, label = ifelse(decades == "1930s" | decades == "1940s" | decades == "1980s" | decades == "1970s", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 6.5, family = "font", color = 'white') + | |
| scale_fill_manual(values = c("#28666e", "#5f2680", "#B5B682", "azure4", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680")) + | |
| labs(x = "", y = "", title = "Share Saying they Definitely Believe in Religious Miracles - by Decade of Birth", caption = "@ryanburge + @religiondata\nData: General Social Survey, 1991-2018") | |
| save("def_miracles_birth_cohort.png", ht = 8, wd = 7) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment