Skip to content

Instantly share code, notes, and snippets.

@ryanburge

ryanburge/never_att_evan.R Secret

Created May 12, 2020
Embed
What would you like to do?
Never attending evangelicals.
gg <- cces18 %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "White Evangelical",
evangelical == 1 & race != 1 ~ "Non-White Evangelical",
mainline == 1 ~ "Mainline",
religpew == 1 & race == 2 ~ "Black Protestant",
catholic == 1 & race == 1 ~ "White Catholic",
catholic == 1 & race != 1 ~ "Non-White Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 5 ~ "Jewish",
religpew == 6 ~ "Muslim",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
TRUE ~ "Unclassified")) %>%
mutate(never = case_when(pew_churatd == 6 ~ 1, TRUE ~ 0)) %>%
group_by(trad2) %>%
mean_ci(never)
gg %>%
ggplot(., aes(x = reorder(trad2, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
y_pct() +
scale_fill_gradient(low = "#E4E5E6", high = "#00416A") +
theme_gg("Abel") +
lab_bar(top = TRUE, type = mean, pos = .04, sz = 4) +
labs(x = "", y = "", title = "Share Who Never Attend Church", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://never_att_trad2.png", type = "cairo-png", width = 7)
gg <- cces18 %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "White Evangelical",
evangelical == 1 & race != 1 ~ "Non-White Evangelical",
mainline == 1 ~ "Mainline",
religpew == 1 & race == 2 ~ "Black Protestant",
catholic == 1 & race == 1 ~ "White Catholic",
catholic == 1 & race != 1 ~ "Non-White Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 5 ~ "Jewish",
religpew == 6 ~ "Muslim",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
TRUE ~ "Unclassified")) %>%
mutate(imp = frcode(pew_religimp == 4 ~ "Not at All",
pew_religimp == 3 ~ "Not too",
pew_religimp == 2 ~ "Somewhat",
pew_religimp == 1 ~ "Very")) %>%
filter(pew_churatd == 6) %>%
group_by(trad2) %>%
ct(imp, show_na = FALSE, wt = commonweight)
lvl <- cces18 %>%
filter(pew_churatd == 6) %>%
mutate(trad2 = frcode(evangelical == 1 & race == 1 ~ "White Evangelical",
evangelical == 1 & race != 1 ~ "Non-White Evangelical",
mainline == 1 ~ "Mainline",
religpew == 1 & race == 2 ~ "Black Protestant",
catholic == 1 & race == 1 ~ "White Catholic",
catholic == 1 & race != 1 ~ "Non-White Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 5 ~ "Jewish",
religpew == 6 ~ "Muslim",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
TRUE ~ "Unclassified")) %>%
mutate(imp = frcode(pew_religimp == 4 ~ "Not at All",
pew_religimp == 3 ~ "Not too",
pew_religimp == 2 ~ "Somewhat",
pew_religimp == 1 ~ "Very")) %>%
group_by(trad2) %>%
ct(imp, wt = commonweight, show_na = FALSE) %>%
filter(imp == "Not at All") %>%
select(trad2, high = pct)
graph <- left_join(gg, lvl)
graph <- graph %>%
ungroup(trad2) %>%
mutate(trad2 = as.factor(trad2))
graph$trad_f <- fct_reorder(graph$trad2, graph$high, .desc = TRUE)
graph %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(imp))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ trad_f, ncol =1, strip.position = "left") +
fill4_3() +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y = element_text(angle = 180)) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Importance of Religion Among Never Attenders", subtitle = "", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://never_religimp.png", width = 9, height = 6)
regg <- cces18 %>%
filter(pew_churatd ==6) %>%
mutate(reltrad = frcode(none == 1 ~ "None",
evangelical == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline",
catholic == 1 ~ "Catholic",
bprot == 1 ~ "Black Prot.",
jewish == 1 ~ "Jewish",
other == 1 ~ "Other",
TRUE ~ "Unclassified")) %>%
mutate(white = case_when(race == 1 ~ 1, TRUE ~ 0)) %>%
mutate(male = case_when(gender == 1 ~ 1, TRUE ~ 0)) %>%
mutate(south = case_when(region == 3 ~ 1, TRUE ~ 0)) %>%
mutate(rep = case_when(pid7 == 5 | pid7 == 6 | pid7 == 7 ~ 1, TRUE ~ 0)) %>%
mutate(age = 2018 - birthyr) %>%
select(reltrad, white, male, south, educ, age, faminc_new, rep)
reg1 <- glm(rep ~ reltrad + white + male + educ + faminc_new + south + age, data = regg, family = "binomial")
coef_names <- c("White" = "black",
"Age" = "age",
"Education" = "educ",
"Male" = "male",
"Income" = "faminc_new",
"South" = "south",
"Evangelical" = "reltradEvangelical",
"Mainline" = "reltradMainline",
"Black Prot." = "reltradBlack Prot.",
"Catholic" = "reltradCatholic",
"Jewish" = "reltradJewish",
"Other Faith" = "reltradOther")
gg <- plot_summs(reg1, scale = TRUE, robust = "HC3", coefs = coef_names, colors = "Qual2")
gg +
theme_gg("Abel") +
labs(y = "", x = "Marginal Effect on Identifying as a Republican", title = "Models Indicate that Never Attending Evangelicals\nAre Distinct From Other Groups") +
ggsave("E://never_attend_evan_reg.png", type = "cairo-png", width = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.