Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created December 9, 2020 18:34
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/9aabda57976d92e96fc484788b98ffdb to your computer and use it in GitHub Desktop.
Save ryanburge/9aabda57976d92e96fc484788b98ffdb to your computer and use it in GitHub Desktop.
RiP Post 12/10/2020
gg <- cces %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1, pew_bornagain == 2 ~ 0)) %>%
cces_trad(religion) %>%
group_by(trad2, year) %>%
mean_ci(ba, wt = weight, ci = .84)
gg %>%
filter(year >= 2008) %>%
filter(trad2 == "White Catholic" | trad2 == "Non-White Catholic" | trad2 == "Mormon" | trad2 == "Orthodox") %>%
ggplot(., aes(x = factor(year), y = mean, fill = trad2)) +
geom_col(color = "black") +
facet_wrap(~ trad2) +
error_bar() +
theme_rb() +
scale_fill_npg() +
lab_bar(top = FALSE, type = mean, pos = .025, sz =4) +
y_pct()+
labs(x = "", y = "", title = "Share Who Identify as Evangelical", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://ba_cces_trad2_series.png", type = "cairo-png")
gg <- cces %>%
filter(pew_bornagain == 1) %>%
group_by(year) %>%
mutate(id5 = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(id5, wt = weight, show_na = FALSE)
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(id5))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("#B2182B","#EF8A62","azure4", "#67A9CF", "#2166AC")) +
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 = "Ideology of Self-Identified Evangelicals", subtitle = "", caption = "@ryanburge\nData: CCES 2006-2018") +
ggsave("E://id5_evan_cces.png", width = 9, height = 5)
gg <- cces %>%
filter(pew_bornagain == 1) %>%
group_by(year) %>%
mutate(pid = frcode(pid7 == 1 ~ "Str. Dem.",
pid7 == 2 ~ "Not Str. Dem.",
pid7 == 3 ~ "Lean Dem.",
pid7 == 4 ~ "Independent",
pid7 == 5 ~ "Lean Rep.",
pid7 == 6 ~ "Not Str. Rep.",
pid7 == 7 ~ "Str. Rep.")) %>%
ct(pid, wt = weight, show_na = FALSE)
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("#8D021F", "#B2182B","#EF8A62","azure4", "#67A9CF", "#2166AC", "#000080", "darkorchid")) +
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") +
geom_text(aes(label = ifelse(pid == "Str. Dem.", paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") +
labs(x = "", y = "", title = "Political Partisanship of Self-Identified Evangelicals", subtitle = "", caption = "@ryanburge\nData: CCES 2006-2019") +
ggsave("E://pid7_evan_cces.png", width = 9, height = 5)
regg <- cces %>%
filter(year == 2008 | year == 2012 | year == 2016 | year == 2019) %>%
mutate(rep = case_when(pid7 == 5 | pid7 == 6 | pid7 == 7 ~ 1,
pid7 <= 4 ~ 0)) %>%
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 = frcode(pew_bornagain == 1 ~ "Evangelical", pew_bornagain == 2 ~ "Not Evangelical")) %>%
mutate(white = case_when(race == 1 ~ 1, TRUE ~ 0)) %>%
mutate(year = as.factor(year)) %>%
mutate(vcon = case_when(ideo5 == 5 ~ 1, ideo5 <= 4 ~ 0)) %>%
mutate(con = case_when(ideo5 == 5 | ideo5 == 4 ~ 1, ideo5 <= 3 ~ 0)) %>%
select(year, rep, male, income, educ, att, ba, white, year, age, vcon, con)
reg1 <- glm(rep ~ att*ba*year + male + white + educ + income + age, data = regg, family = "binomial")
int <- interact_plot(reg1, pred= att, modx = year, mod2= ba, int.width = .76, interval = TRUE, mod2.labels = c("Evangelical", "Not Evangelical"))
int +
y_pct() +
theme_rb(legend = TRUE) +
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Never", "Seldom", "Yearly", "Monthly", "Weekly", "Weekly+")) +
labs(x = "", y = "", title = "Non-Attending Evangelicals are More Republican Than Ever", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://reg_ev_rep.png", type = "cairo-png")
reg1 <- glm(con ~ att*ba*year + male + white + educ + income + age, data = regg, family = "binomial")
int <- interact_plot(reg1, pred= att, modx = year, mod2= ba, int.width = .76, interval = TRUE, mod2.labels = c("Evangelical", "Not Evangelical"))
int +
y_pct() +
theme_rb(legend = TRUE) +
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Never", "Seldom", "Yearly", "Monthly", "Weekly", "Weekly+")) +
labs(x = "", y = "Estimate of Share Who Are Conservative", title = "Non-Attending Evangelicals are More Conservative Than Ever", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://reg_ev_cons.png", type = "cairo-png")
reg <- lm(losses ~ hits + homeruns + atbats + data =df)
gg <- cces %>%
filter(pew_bornagain == 1) %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
cces_attend(pew_attendance) %>%
group_by(year) %>%
ct(att, show_na = FALSE, wt = weight)
gg %>%
filter(year >= 2008) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(att))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1, strip.position = "left") +
scale_fill_paletteer_d("awtools::mpalette") +
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 = "Church Attendance of Self-Identified Evangelical Conservatives", subtitle = "", caption = "@ryanburge\nData: CCES 2008-2018") +
ggsave("E://attend_cons_evan.png", width = 9, height = 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment