-
-
Save ryanburge/d88172825f3b3a1d9dd1d765f1645b9d 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
library(rio) | |
library(janitor) | |
spirit <- import("E://data/state_spiritual.dta") %>% clean_names() | |
god <- spirit %>% | |
mutate(god = q14) %>% | |
mutate(god = frcode(god == 5 ~ "Believe, No Doubts", | |
god == 4 ~ "Believe More than Doubt", | |
god == 3 ~ "Doubt More than Believe", | |
god == 2 ~ "Some Higher Power", | |
god == 1 ~ "Don't Believe")) %>% | |
mutate(gender = frcode(gender == 1 ~ "Men", | |
gender == 2 ~ "Women")) %>% | |
group_by(gender) %>% | |
ct(god, wt = weight, show_na = FALSE) | |
god %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = fct_rev(god), y = pct, fill = gender)) + | |
geom_col(color = "black", position = "dodge") + | |
coord_flip() + | |
theme_rb(legend = TRUE) + | |
scale_fill_manual(values = c("#033f63", "#B5B682")) + | |
y_pct() + | |
geom_text(aes(y = pct + .026, label = ifelse(pct <= .09, paste0(lab*100, '%'),"")), position = position_dodge(width = .9), size = 9, family = "font") + | |
geom_text(aes(y = pct + .03, label = ifelse(pct > .09, paste0(lab*100, '%'),"")), position = position_dodge(width = .9), size = 9, family = "font") + | |
theme(plot.title = element_text(hjust = 2)) + | |
guides(fill = guide_legend(reverse = TRUE)) + | |
labs(x = "", y = "", title = "Which statement comes closest to expressing what you believe about a higher power", caption = "@ryanburge + @religiondata\nData: The National Religion and Spirituality Survey, November 2022") | |
save("belief_god_by_gender.png", ht = 6) | |
heat_m <- spirit %>% | |
mutate(rel = q10) %>% | |
mutate(rel = frcode(rel == 4 ~ "Not at all", | |
rel == 3 ~ "Slightly", | |
rel == 2 ~ "Moderately", | |
rel == 1 ~ "Very")) %>% | |
mutate(spirit = q6) %>% | |
mutate(spirit = frcode(spirit == 4 ~ "Not at all", | |
spirit == 3 ~ "Slightly", | |
spirit == 2 ~ "Moderately", | |
spirit == 1 ~ "Very")) %>% | |
filter(gender == 1) %>% | |
group_by(rel) %>% | |
ct(spirit, wt = weight, show_na = FALSE) %>% | |
filter(rel != "NA") %>% | |
mutate(gender = "Men") %>% | |
mutate(pct = n/1745) | |
heat_f <- spirit %>% | |
mutate(rel = q10) %>% | |
mutate(rel = frcode(rel == 4 ~ "Not at all", | |
rel == 3 ~ "Slightly", | |
rel == 2 ~ "Moderately", | |
rel == 1 ~ "Very")) %>% | |
mutate(spirit = q6) %>% | |
mutate(spirit = frcode(spirit == 4 ~ "Not at all", | |
spirit == 3 ~ "Slightly", | |
spirit == 2 ~ "Moderately", | |
spirit == 1 ~ "Very")) %>% | |
filter(gender == 2) %>% | |
group_by(rel) %>% | |
ct(spirit, wt = weight, show_na = FALSE) %>% | |
filter(rel != "NA") %>% | |
mutate(gender = "Women") %>% | |
mutate(pct = n/1842) | |
heat <- bind_rows(heat_m, heat_f) | |
heat %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x= rel, y = spirit)) + | |
geom_tile(aes(fill = pct), color = "black") + | |
scale_fill_gradient2(low = "#033f63", mid = "#e1e1e1", high = "#FEDC97", midpoint = .1) + | |
facet_wrap(~ gender) + | |
theme_rb() + | |
theme(plot.subtitle = element_text(size = 24)) + | |
geom_text(aes(x= rel, y = spirit, label = paste0(lab*100, '%')), size =12, family = "font") + | |
theme(strip.text = element_text(size = 24)) + | |
labs(x= "How Religious Are You?", y = "How Spiritual Are You?", title = "The Relationship Between Religion and Spirituality Broken Down by Gender", caption = "@ryanburge + @religiondata\nData: The National Religion and Spirituality Survey, November 2022") | |
save('heat_rel_spirit_gender.png', wd = 12) | |
god <- spirit %>% | |
mutate(connect = q16_1) %>% | |
mutate(connect = frcode(connect == 1 ~ "Not at all", | |
connect == 2 ~ "Slightly", | |
connect == 3 ~ "Moderately", | |
connect == 4 ~ "Highly")) %>% | |
mutate(gender = frcode(gender == 1 ~ "Men", | |
gender == 2 ~ "Women")) %>% | |
group_by(gender) %>% | |
ct(connect, wt = weight, show_na = FALSE) | |
god %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = connect, y = pct, fill = gender)) + | |
geom_col(color = "black", position = "dodge") + | |
theme_rb(legend = TRUE) + | |
scale_fill_manual(values = c("#033f63", "#B5B682")) + | |
y_pct() + | |
geom_text(aes(y = pct + .0275, label = ifelse(pct > .09, paste0(lab*100, '%'),"")), position = position_dodge(width = .9), size = 11, family = "font") + | |
theme(plot.title = element_text(size = 24)) + | |
theme(axis.text.x = element_text(size = 20)) + | |
theme(legend.text = element_text(size = 20)) + | |
labs(x = "", y = "", title = "To what extent do you feel connected to a higher power?", caption = "@ryanburge + @religiondata\nData: The National Religion and Spirituality Survey, November 2022") | |
save("connect_higher_power_by_gender.png", ht = 6) | |
fun <- function(var, name){ | |
spirit %>% | |
mutate(gender = frcode(gender == 1 ~ "Men", | |
gender == 2 ~ "Women")) %>% | |
mutate(vv = {{var}}) %>% | |
mutate(vv = case_when(vv == 1 | vv == 2 ~ 1, | |
vv == 3 | vv == 4 | vv == 5 ~ 0)) %>% | |
group_by(gender) %>% | |
mean_ci(vv, ci = .84, wt = weight) %>% | |
mutate(type = name) | |
} | |
var <- syms(c("q19a", "q19b", "q19c", "q19d", "q19e", "q19f", "q19g", "q19h", "q19i", "q19j", "q19k", "q19l", "q19m", "q19n", "q19o", "q19p", "q19q")) | |
name <- c("Prayer", "Yoga/Marital Arts", "Meditation", "Study of Religious Text", "Tarot/Fortune Telling", "Reading", "Fasting", "Attending\nReligious Services", "Attending Other\nReligious/Spiritual Groups", | |
"Art", "Being in Nature", "Writing", "Communicating with\nAncestors", "Offering/Donation", "Acts of Service", "Acts of Protest", "Teaching in\nReligious Setting") | |
gg1 <- map2_df(var, name, fun, .progress = TRUE) | |
gg1 %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = gender, y = mean, fill = gender)) + | |
geom_col(color = "black") + | |
facet_wrap(~ type) + | |
theme_rb() + | |
scale_fill_manual(values = c("#033f63", "#B5B682")) + | |
y_pct() + | |
theme(plot.title = element_text(size = 24)) + | |
geom_text(aes(y = mean + .055, label = ifelse(mean > .00, paste0(lab*100, '%'),"")), position = position_dodge(width = .9), size = 8, family = "font") + | |
labs(x = "", y = "", title = "Enaged in the Following Spiritual Activity in Previous Week", caption = "@ryanburge + @religiondata\nData: The National Religion and Spirituality Survey, November 2022") | |
save("rel_acts_gender_fetzer.png", ht = 12, wd = 9) | |
god <- spirit %>% | |
mutate(doubt = chaps) %>% | |
mutate(doubt = frcode(doubt == 5 ~ "Never", | |
doubt == 4 ~ "Seldom", | |
doubt == 3 ~ "Some of the Time", | |
doubt == 2 ~ "Nearly Always", | |
doubt == 1 ~ "Always")) %>% | |
mutate(gender = frcode(gender == 1 ~ "Men", | |
gender == 2 ~ "Women")) %>% | |
group_by(gender) %>% | |
ct(doubt, wt = weight, show_na = FALSE) | |
god %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(doubt))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ gender, ncol =1, strip.position = "left") + | |
theme_rb() + | |
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97")) + | |
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 = 7, family = "font", color = "black") + | |
geom_text(aes(label = ifelse(doubt == "Nearly Always" | doubt == "Always" & pct > .05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 7, 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(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
labs(x = "", y = "", title = "How often do you have doubts about your religious or spiritual beliefs? ", caption = "@ryanburge + @religiondata\nData: The National Religion and Spirituality Survey, November 2022") | |
save("doubt_by_gender_fetzer.png", wd = 9, ht = 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment