Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created July 14, 2024 20:21
Show Gist options
  • Select an option

  • Save ryanburge/863c165d633824d03f1ee1fe304734c1 to your computer and use it in GitHub Desktop.

Select an option

Save ryanburge/863c165d633824d03f1ee1fe304734c1 to your computer and use it in GitHub Desktop.
gg <- cces %>%
filter(year >= 2022) %>%
cces_id5(ideo5) %>%
cces_attend(pew_attendance) %>%
group_by(att) %>%
ct(id5, wt = weight, show_na = FALSE) %>% filter(att != "NA")
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill =id5)) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ att, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c("#2166AC", "#67A9CF", "azure4", "#EF8A62","#B2182B")) +
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 >.06, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 10, family = "font", color = "black") +
geom_text(aes(label = ifelse(id5 == "Very Conservative", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 10, family = "font", color = "white") +
geom_text(aes(label = ifelse(id5 == "Very Liberal" & pct > .06, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 10, 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 = "Religious Attendance and Political Ideology", caption = "@ryanburge\nData: Cooperative Election Study, 2022-2023")
save("att_id52023.png", wd = 9, ht = 5)
gg <- cces %>%
filter(year >= 2022) %>%
cces_race(race) %>%
cces_attend(pew_attendance) %>%
mutate(lib = case_when(ideo5 == 1 | ideo5 == 2 ~ 1,
ideo5 <= 5 ~ 0)) %>%
group_by(att, race) %>%
mean_ci(lib, wt = weight, ci = .84) %>% filter(att != "NA")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = att, y = mean, fill = race)) +
geom_col(color = "black", position = "dodge") +
facet_wrap(~ race) +
scale_fill_manual(values = c(moma.colors("ustwo", 5))) +
theme_rb() +
y_pct() +
error_bar() +
theme(axis.text.x = element_text(size = 10)) +
lab_bar(top = FALSE, type = lab, pos = .04, sz = 5.5) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "Share Who Identify as Liberal by Race and Religious Attendance", caption = "@ryanburge\nData: Cooperative Election Study, 2022-2023")
save("liberal_race_attend.png")
gg <- cces %>%
filter(year >= 2022) %>%
mutate(trad = frcode(baptist == 1 ~ "Southern Baptist",
baptist == 2 ~ "ABCUSA",
baptist == 3 ~ "Natl. Baptist Convention",
baptist == 4 ~ "Progressive Baptist Convention",
baptist == 5 ~ "Independent Baptist",
baptist == 6 ~ "Baptist General Conference",
baptist == 7 ~ "Baptist Miss. Association",
baptist == 8 ~ "Conservative Bapt. Association",
baptist == 9 ~ "Free Will Baptist",
baptist == 10 ~ "Gen. Assoc. of Reg. Bapt.",
baptist == 90 ~ "Other Baptist",
methodist == 1 ~ "United Methodist",
methodist == 2 ~ "Free Methodist",
methodist == 3 ~ "African Methodist Episcopal",
methodist == 4 ~ "AME - Zion",
methodist == 5 ~ "Christian Methodist Episcopal",
methodist == 90 ~ "Other Methodist",
nondenom == 1 ~ "Nondenom Evangelical",
nondenom == 2 ~ "Nondenom Fundamentalist",
nondenom == 3 ~ "Nondenom Charismatic",
nondenom == 4 ~ "Interdenominational",
nondenom == 5 ~ "Community Church",
nondenom == 90 ~ "Other Nondenom",
lutheran == 1 ~ "ELCA",
lutheran == 2 ~ "Lutheran - Missouri Synod",
lutheran == 3 ~ "Lutheran - Wisconsin Synod",
lutheran == 4 ~ "Other Lutheran",
presbyterian == 1 ~ "PCUSA",
presbyterian == 2 ~ "PCA",
presbyterian == 3 ~ "Associated Reformed Presbyterian",
presbyterian == 4 ~ "Cumberland Presbyterian",
presbyterian == 5 ~ "Orthodox Presbyterian",
presbyterian == 6 ~ "Evangelical Presbyterian",
presbyterian == 90 ~ "Other Presbyterian",
pentecostal == 1 ~ "Assemblies of God",
pentecostal == 2 ~ "Church of God Cleveland TN",
pentecostal == 3 ~ "Four Square Gospel",
pentecostal == 4 ~ "Pentecostal Church of God",
pentecostal == 5 ~ "Pentecostal Holiness Church",
pentecostal == 6 ~ "Church of God in Christ",
pentecostal == 7 ~ "Church of God of the Apostolic Faith",
pentecostal == 8 ~ "Assembly of Christian Churches",
pentecostal == 9 ~ "Apostolic Christian",
pentecostal == 90 ~ "Other Pentecostal",
episcopal == 1 ~ "ECUSA",
episcopal == 2 ~ "Church of England",
episcopal == 3 ~ "Anglican Orthodox",
episcopal == 4 ~ "Reformed Episcopal",
episcopal == 90 ~ "Other Episcopal",
christian == 1 ~ "Church of Christ",
christian == 2 ~ "Disciples of Christ",
christian == 3 ~ "Christian Church",
christian == 90 ~ "Other Christian Church",
congregational == 1 ~ "United Church of Christ",
congregational == 2 ~ "Conservative Cong. Christian",
congregational == 3 ~ "National Assoc. of Cons. Cong.",
congregational == 90 ~ "Other Cong.",
holiness == 1 ~ "Church of the Nazarene",
holiness == 2 ~ "Wesleyan Church",
holiness == 4 ~ "Christian and Missionary Alliance",
holiness == 5 ~ "Church of God",
holiness == 6 ~ "Salvation Army",
reformed == 1 ~ "Reformed Church in America",
reformed == 2 ~ "Christian Reformed",
reformed == 90 ~ "Other Reformed",
adventist == 1 ~ "Seventh Day Adventist")) %>%
cces_attend(pew_attendance) %>%
mutate(lib = case_when(ideo5 == 1 | ideo5 == 2 ~ 1,
ideo5 <= 5 ~ 0)) %>%
group_by(trad, att) %>%
mean_ci(lib, wt = weight, ci = .84) %>%
filter(att != "NA")
gg1 <- gg %>%
group_by(trad) %>%
summarise(sum = sum(n))
both <- left_join(gg, gg1) %>% filter(trad != "NA")
both <- both %>%
filter(sum > 450)
both %>%
ggplot(., aes(x = att, y = mean, fill = trad, group = trad)) +
geom_col(color = "black") +
facet_wrap(~ trad) +
theme_rb() +
y_pct() +
scale_fill_manual(values = c(moma.colors("Panton", 20))) +
scale_x_discrete(breaks = function(x) x[c(TRUE, FALSE)]) +
geom_smooth(se = FALSE, method = lm, color = "black", linetype = "twodash") +
labs(x = "Attendance", y = "", title = "Share Who Identify as Liberal by Church Attendance", subtitle = "Among the 20 Largest Protestant Denominations",
caption = "@ryanburge\nData: Cooperative Election Study, 2022-2023")
save("att_liberal_top20.png", ht = 11)
gg <- cces %>%
filter(year >= 2020) %>%
mutate(rel = frcode(religion == 2 ~ "Catholic",
religion == 3 ~ "LDS",
religion == 5 ~ "Jewish",
religion == 6 ~ "Muslim",
religion == 7 ~ "Buddhist",
religion == 8 ~ "Hindu")) %>%
cces_attend(pew_attendance) %>%
group_by(rel, att) %>%
mutate(lib = case_when(ideo5 == 1 | ideo5 == 2 ~ 1,
ideo5 <= 5 ~ 0)) %>%
mean_ci(lib, wt = weight, ci = .84) %>%
filter(att != "NA") %>%
filter(rel != "NA")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = att, y = mean, fill = rel)) +
geom_col(color = "black", position = "dodge") +
facet_wrap(~ rel) +
scale_fill_manual(values = c(moma.colors("Connors", 6))) +
theme_rb() +
y_pct() +
error_bar() +
theme(axis.text.x = element_text(size = 10)) +
lab_bar(top = FALSE, type = lab, pos = .04, sz = 5.5) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "Share Who Identify as Liberal by Religious Attendance", caption = "@ryanburge\nData: Cooperative Election Study, 2020-2023")
save("liberal_non_protestant_attend.png", ht = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment