Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created November 18, 2024 04:02
Show Gist options
  • Save ryanburge/849132ac41b55a13077076551bb83856 to your computer and use it in GitHub Desktop.
Save ryanburge/849132ac41b55a13077076551bb83856 to your computer and use it in GitHub Desktop.
library(rio)
library(janitor)
chap <- import("E://data/chaplains.sav") %>% clean_names()
gg <- chap %>%
mutate(cc = q310) %>%
mutate(cc = frcode(cc == 4 ~ "No",
cc == 3 ~ "Both Virtual and In-Person",
cc == 2 ~ "Yes, Virtually",
cc == 1 ~ "Yes, in Person")) %>%
ct(cc, show_na = FALSE, wt = weight)
custom_palette <- c(
"#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00",
"#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5",
"#FC8D62", "#8DA0CB", "#E78AC3"
)
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = cc, y = pct, fill = cc)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
geom_text(aes(y = pct + .035, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") +
theme(plot.title = element_text(size = 14)) +
labs(x = "", y = "", title = "Has a chaplain EVER assisted, counseled, or visited with you, either in person or virtually?",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_2022.png", ht = 3.5)
gg <- chap %>%
mutate(how = q402_coded) %>%
mutate(how = frcode(how == 1 ~ "Chaplain Initiated",
how == 2 ~ "I Requested",
how == 3 ~ "Referral",
how == 4 ~ "Incidental",
how == 6 | how == 9 ~ "Other",
how == 5 ~ "Prior Relationship")) %>%
ct(how, show_na = FALSE, wt = weight)
custom_palette <- c(
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5",
"#FC8D62", "#8DA0CB", "#E78AC3"
)
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = fct_rev(how), y = pct, fill = how)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
geom_text(aes(y = pct + .02, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") +
theme(plot.title = element_text(size = 20)) +
labs(x = "", y = "", title = "How was your interaction with the chaplain initiated?",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_how_initiated.png", ht = 5)
library(dplyr)
# Template for processing each question
results <- list()
results$passages <- chap %>%
mutate(vv = q420a) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Passages from Religious or Spiritual Texts")
results$death <- chap %>%
mutate(vv = q420b) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Death and Dying")
results$change <- chap %>%
mutate(vv = q420c) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Dealing with Change")
results$meaning <- chap %>%
mutate(vv = q420d) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "The Meaning of Life")
results$physical_health <- chap %>%
mutate(vv = q420e) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Your Physical Health")
results$mental_health <- chap %>%
mutate(vv = q420f) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Your Mental or Emotional Health")
results$coronavirus <- chap %>%
mutate(vv = q420g) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Coronavirus/Pandemic")
results$relationships <- chap %>%
mutate(vv = q420h) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Relationship Issues")
results$family <- chap %>%
mutate(vv = q420i) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Family Dynamics")
results$religious_views <- chap %>%
mutate(vv = q420j) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Your Religious Views")
results$loss <- chap %>%
mutate(vv = q420k) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Dealing with Loss")
results$moral <- chap %>%
mutate(vv = q420l) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight, ci = .84) %>%
mutate(type = "Moral or Ethical Concerns")
# Combine all results into a single dataframe
final_results <- bind_rows(results)
custom_palette <- c(
"#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00",
"#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5",
"#FC8D62", "#8DA0CB", "#E78AC3"
)
final_results %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(type, mean), y = mean, fill = type)) +
geom_col(color = "black") +
coord_flip() +
error_bar() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
lab_bar(top = FALSE, type = lab, pos = .035, sz = 8) +
labs(x = "", y = "Share Saying Yes", title = "Were the Following Topics Discussed With the Chaplain?",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_topics_discussed.png")
library(dplyr)
# Template for processing each question
results <- list()
results$compassionate <- chap %>%
mutate(vv = q440a) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Compassionate")
results$listener <- chap %>%
mutate(vv = q440b) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "A Good Listener")
results$spiritual <- chap %>%
mutate(vv = q440c) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Spiritual")
results$helpful <- chap %>%
mutate(vv = q440d) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Helpful")
results$knowledgeable <- chap %>%
mutate(vv = q440e) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Knowledgeable")
results$trustworthy <- chap %>%
mutate(vv = q440f) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Trustworthy")
results$pushy <- chap %>%
mutate(vv = q440g) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Pushy")
results$condescending <- chap %>%
mutate(vv = q440h) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Condescending")
results$intrusive <- chap %>%
mutate(vv = q440i) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = weight) %>%
mutate(type = "Intrusive")
# Combine all results into a single dataframe
final_results <- bind_rows(results)
custom_palette <- c(
"#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00",
"#FFFF33", "#A65628", "#F781BF", "#999999", "#66C2A5",
"#FC8D62", "#8DA0CB", "#E78AC3"
)
final_results %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(type, mean), y = mean, fill = type)) +
geom_col(color = "black") +
coord_flip() +
error_bar() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
lab_bar(top = FALSE, type = lab, pos = .045, sz = 8) +
labs(x = "", y = "Share Saying Yes", title = "Would you describe the chaplain you interacted with as:",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_characteristics.png")
gg <- chap %>%
mutate(cc = q310) %>%
mutate(cc = case_when(cc == 1 | cc == 2 | cc == 3 ~ 1,
cc == 4 ~ 0)) %>%
cces_attend(attend) %>%
group_by(att) %>%
mean_ci(cc, ci = .84, wt = weight) %>%
na.omit()
custom_palette <- c(
"#A65628", "#999999", "#66C2A5",
"#FC8D62", "#8DA0CB", "#E78AC3"
)
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = att, y = mean, fill = att)) +
geom_col(color = "black") +
coord_flip() +
error_bar() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
lab_bar(top = FALSE, type = lab, pos = .035, sz = 10) +
labs(x = "", y = "", title = "Share Saying They Met With a Chaplain by Religious Attendance",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_att_meet.png", ht = 5)
gg <- chap %>%
mutate(cc = q310) %>%
mutate(cc = case_when(cc == 1 | cc == 2 | cc == 3 ~ 1,
cc == 4 ~ 0)) %>%
mutate(rel = relper) %>%
mutate(rel = frcode(rel == 1 ~ "Not At All",
rel == 2 ~ "Not Too",
rel == 3 ~ "Somewhat",
rel == 4 ~ "Very",
rel == 5 ~ "Extremely")) %>%
group_by(rel) %>%
mean_ci(cc, ci = .84, wt = weight) %>%
na.omit()
custom_palette <- c(
"#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = rel, y = mean, fill = rel)) +
geom_col(color = "black") +
coord_flip() +
error_bar() +
theme_rb() +
y_pct() +
scale_fill_manual(values = custom_palette) +
lab_bar(top = FALSE, type = lab, pos = .035, sz = 10) +
labs(x = "", y = "", title = "Share Saying They Met With a Chaplain by Self Described Religiosity",
caption = "@ryanburge + @religiondata\nData: Survey of Demand for Chaplaincy, 2022")
save("chaplain_relperson_meet.png", ht = 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment