Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created April 2, 2024 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/500d9ee117ca10e9b90778c1ad9c3a20 to your computer and use it in GitHub Desktop.
Save ryanburge/500d9ee117ca10e9b90778c1ad9c3a20 to your computer and use it in GitHub Desktop.
library(rio)
library(janitor)
gss <- import("E://data/gss12.dta")
gss <- gss %>%
filter(rdscmost == 1)
aaa1 <- gss %>%
mutate(pros = rdscwlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Wealth or Prosperity")
aaa2 <- gss %>%
mutate(pros = rdschlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Health or Healing")
both <- bind_rows(aaa1, aaa2)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pros1))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "top") +
theme_rb() +
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#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 = 9, family = "font", color = "black") +
geom_text(aes(label = ifelse(pros1 == "To a great extent", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 9, family = "font", color = "white") +
geom_text(aes(label = ifelse(pros1 == "To a considerable extent", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 9, 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)) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "To what extent did you read the Bible to...", caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("prosperity_gss_arda.png", wd = 9, ht = 3.5)
aaa1 <- gss %>%
mutate(rac2 = frcode(race == 1 ~ "White",
TRUE ~ "Non-White")) %>%
mutate(pros = rdscwlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
group_by(rac2) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Wealth or Prosperity")
aaa2 <- gss %>%
mutate(rac2 = frcode(race == 1 ~ "White",
TRUE ~ "Non-White")) %>%
mutate(pros = rdschlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
group_by(rac2) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Health or Healing")
both <- bind_rows(aaa1, aaa2)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = fct_rev(rac2), y = pct, fill = fct_rev(pros1))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "top") +
theme_rb() +
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#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 = 9, family = "font", color = "black") +
geom_text(aes(label = ifelse(pct >.05 & pros1 == "To a great extent", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 9, family = "font", color = "white") +
geom_text(aes(label = ifelse(pct >.05 & pros1 == "To a considerable extent", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 9, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "To what extent did you read the Bible to...", caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("prosperity_gss_arda_race.png", wd = 9, ht = 4.5)
aaa1 <- gss %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(pros = rdscwlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
group_by(gender) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Wealth or Prosperity")
aaa2 <- gss %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
mutate(pros = rdschlth) %>%
mutate(pros1 = frcode(pros == 1 ~ "Not at All",
pros == 2 ~ "To a small extent",
pros == 3 ~ "To a moderate extent",
pros == 4 ~ "To a considerable extent",
pros == 5 ~ "To a great extent")) %>%
group_by(gender) %>%
ct(pros1, show_na = FALSE) %>%
mutate(type = "To Learn About Attaining Health or Healing")
both <- bind_rows(aaa1, aaa2)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = fct_rev(gender), y = pct, fill = fct_rev(pros1))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "top") +
theme_rb() +
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#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 = 9, family = "font", color = "black") +
geom_text(aes(label = ifelse(pct >.05 & pros1 == "To a great extent", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 9, 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)) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "To what extent did you read the Bible to...", caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("prosperity_gss_arda_gender.png", wd = 9, ht = 4.5)
aaa1 <- gss %>%
mutate(pros = rdscwlth) %>%
mutate(pros = case_when(pros == 2 | pros == 3 | pros == 4 | pros == 5 ~ 1,
pros == 1 ~ 0)) %>%
mutate(income = INCOME06) %>%
mutate(inc = frcode(income <= 8 ~ "<$10K",
income >= 9 & income <= 12 ~ "$10K-$20K",
income >= 13 & income <= 15 ~ "$20K-$30K",
income == 16 | income == 17 ~ "$30K-$40K",
income == 18 ~ "$40K-$50K",
income == 19 ~ "$50K-$60K",
income == 20 ~ "$60K-$75K",
income == 21 ~ "$75K-$90K",
income == 22 ~ "$90K-$110K",
income == 23 | income == 24 ~ "$110K-$150K",
income == 25 ~ "$150K+")) %>%
group_by(inc) %>%
mean_ci(pros, ci = .84) %>%
mutate(type = "Wealth/Prosperity") %>%
na.omit()
aaa2 <- gss %>%
mutate(pros = rdschlth) %>%
mutate(pros = case_when(pros == 2 | pros == 3 | pros == 4 | pros == 5 ~ 1,
pros == 1 ~ 0)) %>%
mutate(income = INCOME06) %>%
mutate(inc = frcode(income <= 8 ~ "<$10K",
income >= 9 & income <= 12 ~ "$10K-$20K",
income >= 13 & income <= 15 ~ "$20K-$30K",
income == 16 | income == 17 ~ "$30K-$40K",
income == 18 ~ "$40K-$50K",
income == 19 ~ "$50K-$60K",
income == 20 ~ "$60K-$75K",
income == 21 ~ "$75K-$90K",
income == 22 ~ "$90K-$110K",
income == 23 | income == 24 ~ "$110K-$150K",
income == 25 ~ "$150K+")) %>%
group_by(inc) %>%
mean_ci(pros, ci = .84) %>%
mutate(type = "Health/Healing") %>%
na.omit()
both <- bind_rows(aaa1, aaa2)
both %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = inc, y = mean, fill = type)) +
geom_col(position = "dodge", color = "black") +
coord_flip() +
scale_fill_manual(values = c("#033f63", "#FEDC97")) +
error_bar() +
y_pct() +
lab_bar(top = FALSE, type = lab, pos = .04, sz = 8) +
geom_text(aes(y = .04, label = ifelse(type == "Health/Healing", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 8, family = "font", color = "white") +
theme_rb(legend = TRUE) +
labs(x = "", y = "Share Agreeing At Least to a Small Extent", title = "To what extent did you read the Bible to Learn About...", caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("pros_gospel_arda_income.png", ht = 10)
gg <- gss %>%
mutate(pros1 = rdschlth) %>%
mutate(pros2 = rdscwlth) %>%
mutate(prosper = pros1 + pros2) %>%
mutate(prosper = prosper - 2) %>%
mutate(income = INCOME06) %>%
mutate(rac2 = frcode(race == 1 ~ "White",
TRUE ~ "Non-White")) %>%
mutate(inc = frcode(income <= 8 ~ "<$10K",
income >= 9 & income <= 12 ~ "$10K-$20K",
income >= 13 & income <= 15 ~ "$20K-$30K",
income == 16 | income == 17 ~ "$30K-$40K",
income == 18 ~ "$40K-$50K",
income == 19 ~ "$50K-$60K",
income == 20 ~ "$60K-$75K",
income == 21 ~ "$75K-$90K",
income == 22 ~ "$90K-$110K",
income == 23 | income == 24 ~ "$110K-$150K",
income == 25 ~ "$150K+")) %>%
group_by(inc, rac2) %>%
mean_ci(prosper, ci = .84) %>%
filter(inc != "NA")
gg %>%
mutate(lab = round(mean, 1)) %>%
ggplot(., aes(x = inc, y = mean, fill = rac2, group = rac2)) +
geom_col(color = "black", position = "dodge") +
error_bar() +
scale_fill_manual(values = c("#033f63", "#FEDC97")) +
theme_rb(legend = TRUE) +
geom_text(aes(y = .5, label = lab), position = position_dodge(width = .9), size = 6, family = "font") +
geom_text(aes(y = .5, label = ifelse(rac2 == "White", lab, "")), position = position_dodge(width = .9), size = 6, family = "font", color = "white") +
labs(x = "Household Income", y = "Prosperity Gospel Index",
subtitle = "Scale Runs from 0 to 8",
title = "Belief in the Prosperity Gospel by Race and Income",
caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("pros_gospel_arda.png")
regg <- gss %>%
mutate(pros1 = rdschlth) %>%
mutate(pros2 = rdscwlth) %>%
mutate(prosper = pros1 + pros2) %>%
mutate(prosper = prosper - 2) %>%
mutate(white = case_when(race == 1 ~ 1,
TRUE ~ 0)) %>%
mutate(male = case_when(sex == 1 ~ 1,
sex == 2 ~ 0)) %>%
mutate(dem = case_when(partyid <= 2 ~ 1,
partyid <= 6 ~ 0)) %>%
select(prosper, white, male, educ, income = INCOME06, attend, dem, age)
out <- lm(prosper ~ white + male + educ + income + attend + dem + age, data = regg)
library(jtools)
coef_names <- c("White" = "white",
"Income" = "income",
"Education" = "educ",
"Age" = "age",
"Male" = "male",
"Democrat" = "dem",
"Church Attendance" = "attend")
gg <- plot_summs(out, scale = TRUE, robust = "HC3", coefs = coef_names, colors = "#5f2680")
gg +
theme_rb() +
add_text(x = -1.5, y = 3.5, word = "Less Belief in PG", sz = 9) +
labs(x = "", y = "", title = "What Factors Lead to More Adherence to the Prosperity Gospel?", caption = "@ryanburge + @religiondata\nData: General Social Survey, 2012")
save("reg_prosperity_arda.png", ht = 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment