Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Last active Mar 2, 2021
Embed
What would you like to do?
BA Muslims
gg <- cces %>%
cces_trad(religion) %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
group_by(trad2, year) %>%
mean_ci(ba, wt = weight, ci = .84) %>%
filter(trad2 == "Muslim")
gg %>%
ggplot(., aes(x = factor(year), y = mean, fill = mean)) +
geom_col(color = "black") +
error_bar() +
lab_bar(top = FALSE, type = mean, pos = .025, sz = 5.5) +
theme_rb() +
y_pct() +
scale_fill_gradient_tableau() +
labs(x = "", y = "", title = "Share of Muslims Who Identify as Evangelical/Born-Again", caption = "@ryanburge\nData: CCES 2006-2019") +
ggsave("E://muslim_born_again.png", type = 'cairo-png')
gg <- cces %>%
filter(religion == 6) %>%
mutate(ba = frcode(pew_bornagain == 1 ~ "Born-Again/Evangelical",
pew_bornagain == 2 ~ "Not BA/Evan.")) %>%
mutate(ed = frcode(educ == 1 ~ "No HS",
educ == 2 ~ "HS Grad",
educ == 3 ~ "Some College",
educ == 4 ~ "2 Yr.",
educ == 5 ~ "4 Yr.",
educ == 6 ~ "Grad School")) %>%
group_by(ba) %>%
ct(ed, wt = weight, show_na = FALSE) %>%
na.omit()
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(ed))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ ba, ncol =1, strip.position = "left") +
scale_fill_d3() +
theme_rb() +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Education Breakdown of Muslims by BA Status", caption = "@ryanburge\nData: CCES 2006-2019") +
ggsave("E://muslim_born_again_educ.png", type = 'cairo-png', height = 3)
gg <- cces %>%
filter(religion == 6) %>%
mutate(ba = frcode(pew_bornagain == 1 ~ "Born-Again/Evangelical",
pew_bornagain == 2 ~ "Not BA/Evan.")) %>%
cces_attend(pew_attendance) %>%
group_by(ba) %>%
ct(att, wt = weight, show_na = FALSE) %>%
na.omit()
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(att))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ ba, ncol =1, strip.position = "left") +
scale_fill_tableau() +
theme_rb() +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Mosque Attendance Breakdown of Muslims by BA Status", caption = "@ryanburge\nData: CCES 2006-2019") +
ggsave("E://muslim_born_again_att.png", type = 'cairo-png', height = 3)
gg <- cces %>%
filter(religion ==6) %>%
mutate(male = case_when(gender == 1 ~ 1,
gender == 2 ~ 0)) %>%
mutate(att = car::recode(pew_attendance, "6=1; 5=2; 4=3; 3=4; 2=5; 1=6; else = NA")) %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
mutate(ed2 = frcode(educ == 5 | educ == 6 ~ "College Grad",
educ <= 4 ~ "No College")) %>%
cces_pid3(pid7) %>%
select(male, att, ba, ed2, income, ed2, educ, pid3)
graph <- glm(ba ~ pid3*att + educ + income + male, data = gg, family = "binomial")
reg <- interact_plot(graph, pred= att, modx = pid3, int.width = .76, interval = TRUE)
reg +
theme_rb(legend = TRUE) +
pid3_fill() +
pid3_color() +
y_pct() +
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Never", "Seldom", "Yearly", "Monthly", "Weekly", "Weekly+")) +
labs(x = "", y = "", title = "Likelihood of a Muslim Identifying as Evangelical/Born-Again", caption = "@ryanburge\nData: CCES 2006-2019") +
ggsave("E://ba_muslim_interact.png", type = 'cairo-png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment