-
-
Save ryanburge/bcf4d5fa364f16731814aa5b192475a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gg <- cces %>% | |
| filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022 | year == 2023) %>% | |
| filter(pew_bornagain == 1) %>% | |
| cces_attend(pew_attendance) %>% | |
| group_by(year) %>% | |
| ct(att, wt = weight, show_na = FALSE) | |
| gg %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(., aes(x = 1, y = pct, fill = fct_rev(att))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ year, ncol =1, strip.position = "left") + | |
| theme_rb() + | |
| scale_fill_manual(values = c(moma.colors("OKeeffe", 6))) + | |
| 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 = 8, family = "font", color = "black") + | |
| geom_text(aes(label = ifelse(att == "Seldom", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
| geom_text(aes(label = ifelse(att == "Yearly", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
| geom_text(aes(label = ifelse(att == "Never" & pct > .05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, 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 = "The Church Attendance of Self-Identified Evangelicals", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
| save("att_evangelical_2023.png", wd = 9, ht = 4) | |
| gg <- cces %>% | |
| filter(year >= 2008) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| group_by(year) %>% | |
| mean_ci(both, wt = weight, ci = .84) | |
| gg %>% | |
| mutate(lab = round(mean, 3)) %>% | |
| ggplot(., aes(x = year, y = mean, fill = mean)) + | |
| geom_col(color = "black") + | |
| theme_rb() + | |
| error_bar() + | |
| scale_fill_gradient(low = "#009FFF", high = "#ec2F4B") + | |
| scale_y_continuous(labels = percent) + | |
| lab_bar(top = FALSE, type = lab, pos = .0075, sz = 5.25) + | |
| labs(x = "", y = "", title = "Share of the Public Who Are Self-Identified Evangelicals Who Attend Church Seldom or Never", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
| save("low_attend_evangelical_over_time.png") | |
| gg <- cces %>% | |
| filter(year >= 2008) %>% | |
| mutate(id3 = frcode(ideo5 == 1 | ideo5 == 2 ~ "Liberal", | |
| ideo5 == 3 ~ "Moderate", | |
| ideo5 == 4 | ideo5 == 5 ~ "Conservative")) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| group_by(year, id3) %>% | |
| mean_ci(both, wt = weight, ci = .84) %>% filter(id3 != 'NA') | |
| gg %>% | |
| mutate(lab = round(mean, 3)) %>% | |
| ggplot(., aes(x = year, y = mean, color = id3)) + | |
| geom_line() + | |
| geom_point(stroke = 1, shape = 21, fill = "white") + | |
| geom_text(data = . %>% filter(year == 2023), | |
| aes(label = scales::percent(mean, accuracy = 0.1)), | |
| vjust = -0.5, size = 5, family = "font", show.legend = FALSE) + | |
| geom_text(data = . %>% filter(year == 2008), | |
| aes(label = scales::percent(mean, accuracy = 0.1)), | |
| hjust = 1.1, vjust = -.1, size = 5, family = "font", show.legend = FALSE) + | |
| theme_rb(legend = TRUE) + | |
| pid3_color() + | |
| scale_y_continuous(labels = scales::percent, limits = c(0, .14)) + | |
| labs(x = "", y = "", title = "Share of the Public Who Are Self-Identified Evangelicals Who Attend Church Seldom or Never", | |
| caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
| save("low_attend_evangelical_over_time_id3.png") | |
| gg <- cces %>% | |
| filter(year >= 2008) %>% | |
| mutate(ed2 = frcode(educ == 1 | educ == 2 ~ "HS or Less", | |
| educ == 5 | educ == 6 ~ "College Grad.")) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| group_by(year, ed2) %>% | |
| mean_ci(both, wt = weight, ci = .84) %>% filter(ed2 != 'NA') | |
| gg %>% | |
| mutate(lab = round(mean, 3)) %>% | |
| ggplot(., aes(x = year, y = mean, color = ed2)) + | |
| geom_line() + | |
| scale_color_calc() + | |
| geom_point(stroke = 1, shape = 21, fill = "white") + | |
| geom_text(data = . %>% filter(year == 2008 | year == 2023), | |
| aes(label = scales::percent(mean, accuracy = 0.1)), | |
| vjust = -0.5, size = 5, family = "font", show.legend = FALSE) + | |
| theme_rb(legend = TRUE) + | |
| scale_y_continuous(labels = scales::percent, limits = c(0, .16)) + | |
| labs(x = "", y = "", title = "Share of the Public Who Are Self-Identified Evangelicals Who Attend Church Seldom or Never", | |
| caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
| save("low_attend_evangelical_over_time_ed2.png") | |
| gg <- cces %>% | |
| filter(year >= 2008) %>% | |
| cces_race(race) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| group_by(year, race) %>% | |
| mean_ci(both, wt = weight, ci = .84) %>% filter(race != 'All Others') | |
| gg %>% | |
| mutate(lab = round(mean, 3)) %>% | |
| ggplot(., aes(x = year, y = mean, color = race)) + | |
| geom_line() + | |
| scale_color_gdocs() + | |
| geom_point(stroke = 1, shape = 21, fill = "white") + | |
| geom_text(data = . %>% filter(year == 2008 | year == 2023), | |
| aes(label = scales::percent(mean, accuracy = 0.1)), | |
| vjust = -0.5, size = 5, family = "font", show.legend = FALSE) + | |
| theme_rb(legend = TRUE) + | |
| scale_y_continuous(labels = scales::percent, limits = c(0, .12)) + | |
| labs(x = "", y = "", title = "Share of the Public Who Are Self-Identified Evangelicals Who Attend Church Seldom or Never", | |
| caption = "@ryanburge\nData: Cooperative Election Study, 2008-2023") | |
| save("low_attend_evangelical_over_time_race.png") | |
| regg <- cces %>% | |
| filter(income <= 16) %>% | |
| filter(year >= 2020) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| mutate(white = case_when(race == 1 ~ 1, | |
| TRUE ~ 0)) %>% | |
| mutate(male = case_when(gender == 1 ~ 1, | |
| gender == 2 ~ 0)) %>% | |
| mutate(cons = case_when(ideo5 == 4 | ideo5 == 5 ~ 1, | |
| ideo5 == 3 | ideo5 == 2 | ideo5 == 1 ~ 0)) %>% | |
| select(both, white, male, cons, educ, income, age) | |
| out <- glm(both ~ ., data = regg, family = "binomial") | |
| coef_names <- c("White" = "white", | |
| "Income" = "income", | |
| "Education" = "educ", | |
| "Age" = "age", | |
| "Male" = "male", | |
| "Conservative" = "cons") | |
| library(jtools) | |
| gg <- plot_summs(out, scale = TRUE, robust = "HC3", coefs = coef_names, colors = "firebrick3") | |
| gg + | |
| theme_rb() + | |
| # # add_text(x = -.5, y = 3.5, word = "Less Agreement", sz = 9) + | |
| # add_text(x = .85, y = 11.5, word = "More Agreement", sz = 9) + | |
| labs(x = "", y = "", title = "Predicting the Likelihood of Being a Low Attending Evangelical", | |
| caption = "@ryanburge\nData: Cooperative Election Study, 2020-2023") | |
| save("reg_ev_low_attend.png", ht = 4) | |
| regg <- cces %>% | |
| filter(income <= 16) %>% | |
| filter(year >= 2020) %>% | |
| mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
| pew_bornagain == 2 ~ 0)) %>% | |
| mutate(low = case_when(pew_attendance == 6 | pew_attendance == 5 ~ 1, | |
| pew_attendance <= 4 ~ 0)) %>% | |
| mutate(both = ba + low) %>% | |
| mutate(both = case_when(both == 2 ~ 1, | |
| both == 1 | both == 0 ~ 0)) %>% | |
| cces_race(race) %>% | |
| mutate(male = case_when(gender == 1 ~ 1, | |
| gender == 2 ~ 0)) %>% | |
| mutate(id3 = frcode(ideo5 == 1 | ideo5 == 2 ~ "Liberal", | |
| ideo5 == 3 ~ "Moderate", | |
| ideo5 == 4 | ideo5 == 5 ~ "Conservative")) %>% | |
| select(both, race, male, id3, educ, income, age) | |
| out <- glm(both ~ race*id3 + ., data = regg, family = "binomial") | |
| library(interactions) | |
| gg <- cat_plot(out, pred = race, modx = id3, interval = TRUE, int.width = .76, errorbar.width = .1, geom = "bar") | |
| gg + | |
| theme_rb(legend = TRUE) + | |
| scale_y_continuous(labels = percent) + | |
| pid3_fill() + | |
| pid3_color() + | |
| labs(x = "", y = "", title = "Predicting the Likelihood of Being a Low Attending Evangelical by Political Ideology", | |
| caption = "@ryanburge\nData: Cooperative Election Study, 2020-2023") | |
| save("reg_ev_low_attend_id3.png", ht = 6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment