Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created February 4, 2024 18:24
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/9ea34c92e4792223fb4d9f27bc72d38b to your computer and use it in GitHub Desktop.
Save ryanburge/9ea34c92e4792223fb4d9f27bc72d38b to your computer and use it in GitHub Desktop.
gg <- cces %>%
filter(year >= 2020) %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
mutate(religpew = religion) %>%
mutate(trad = frcode(religpew == 1 ~ "Protestant",
religpew == 2 ~ "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",
religpew == 12 ~ "Something Else")) %>%
group_by(trad) %>%
mean_ci(ba, ci = .84) %>% filter(trad != "NA")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(trad, mean), y = mean, fill = trad)) +
geom_col(color = 'black') +
coord_flip() +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_manual(values = c(moma.colors("Warhol", 12))) +
lab_bar(top = FALSE, type = lab, pos = .03, sz = 7) +
labs(x = "", y = "Share Answering Yes", title = "Would you describe yourself as a 'born-again' or evangelical Christian, or not?", caption = "@ryanburge\nData: Cooperative Election Study, 2022")
save("ces_ba_22_all_trads.png")
gg <- ns %>%
mutate(ba = case_when(is_evangelical == 1 ~ 1,
is_evangelical == 2 ~ 0)) %>%
mutate(trad = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 3 ~ "Mormon",
religion == 4 ~ "Orthodox",
religion == 6 ~ "Jewish",
religion == 7 ~ "Muslim",
religion == 8 ~ "Buddhist",
religion == 9 ~ "Hindu",
religion == 10 ~ "Atheist",
religion == 11 ~ "Agnostic",
religion == 12 ~ "Nothing in Particular",
religion == 13 ~ "Something Else",
religion == 5 ~ "Christian, Other than Above")) %>%
group_by(trad) %>%
mean_ci(ba, ci = .84) %>% filter(trad != "NA")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(trad, mean), y = mean, fill = trad)) +
geom_col(color = 'black') +
coord_flip() +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_manual(values = c(moma.colors("Warhol", 13))) +
lab_bar(top = FALSE, type = lab, pos = .03, sz = 7) +
geom_text(aes(y = .03, label = ifelse(trad == "Christian, Other than Above", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 7, family = "font", color = "white") +
labs(x = "", y = "Share Answering Yes", title = "Would you describe yourself as a 'born-again' or evangelical Christian, or not?", caption = "@ryanburge\nData: Nationscape, 2019-2021")
save("ns_ba_all_trads.png")
gg <- cces %>%
filter(year == 2012 | year == 2016 | year == 2020 | year == 2022) %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
mutate(religpew = religion) %>%
mutate(trad = frcode(religpew == 1 ~ "Protestant",
religpew == 2 ~ "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",
religpew == 12 ~ "Something Else")) %>%
group_by(trad, year) %>%
mean_ci(ba, ci = .84) %>% filter(trad != "NA")
gg %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = factor(year), y = mean, fill = trad)) +
geom_col(color = "black") +
facet_wrap(~ trad) +
y_pct() +
theme_rb() +
scale_fill_manual(values = c(moma.colors("Warhol", 12))) +
lab_bar(top = FALSE, type = lab, pos = .075, sz = 6) +
error_bar() +
labs(x = "", y = "Share Answering Yes", title = "Would you describe yourself as a 'born-again' or evangelical Christian, or not?", caption = "@ryanburge\nData: Cooperative Election Study, 2012-2022")
save("ba_all_trads_over_time.png")
cces_pid3 <- function(df, var){
df %>%
mutate(pid3 = frcode({{var}} == 1 | {{var}} == 2 | {{var}} == 3 ~ "Dem",
{{var}} == 4 ~ "Ind",
{{var}} == 5 | {{var}} == 6 | {{var}} == 7 ~ "Rep"))
}
graph <- cces %>%
filter(year >= 2018) %>%
mutate(ba = case_when(pew_bornagain == 1 ~ 1,
pew_bornagain == 2 ~ 0)) %>%
cces_pid3(pid7) %>%
mutate(religpew = religion) %>%
mutate(trad = frcode(religpew == 1 ~ "Protestant",
religpew == 2 ~ "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",
religpew == 12 ~ "Something Else")) %>%
group_by(trad, pid3) %>%
mean_ci(ba, ci = .84) %>%
filter(trad != 'NA') %>%
filter(pid3 != "NA")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = pid3, y = mean, fill = pid3)) +
geom_col(color = "black") +
facet_wrap(~ trad) +
pid3_fill() +
theme_rb() +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = lab, pos = .06, sz = 5) +
theme(plot.title = element_text(size = 12)) +
labs(x = "", y = "Share Answering Yes", title = "Would you describe yourself as a 'born-again' or evangelical Christian, or not?", caption = "@ryanburge\nData: Cooperative Election Study, 2018-2022")
save("pid3_ba_all_trads_ces.png", wd = 6)
graph <- ns %>%
mutate(ba = case_when(is_evangelical == 1 ~ 1,
is_evangelical == 2 ~ 0)) %>%
cces_pid3(pid7_legacy) %>%
mutate(trad = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 3 ~ "Mormon",
religion == 4 ~ "Orthodox",
religion == 5 ~ "Christian",
religion == 6 ~ "Jewish",
religion == 7 ~ "Muslim",
religion == 8 ~ "Buddhist",
religion == 9 ~ "Hindu",
religion == 10 ~ "Atheist",
religion == 11 ~ "Agnostic",
religion == 12 ~ "Nothing in Particular",
religion == 13 ~ "Something Else")) %>%
group_by(trad, pid3) %>%
mean_ci(ba, ci = .84) %>%
filter(trad != 'NA') %>%
filter(pid3 != "NA")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = pid3, y = mean, fill = pid3)) +
geom_col(color = "black") +
facet_wrap(~ trad) +
pid3_fill() +
theme_rb() +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = lab, pos = .075, sz = 5) +
theme(plot.title = element_text(size = 12)) +
labs(x = "", y = "Share Answering Yes", title = "Would you describe yourself as a 'born-again' or evangelical Christian, or not?", caption = "@ryanburge\nData: Nationscape, 2019-2021")
save("pid3_ba_all_trads_ns.png", wd = 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment