Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Last active December 7, 2020 17:10
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/82839451f8a619c31504f507a562c63c to your computer and use it in GitHub Desktop.
Save ryanburge/82839451f8a619c31504f507a562c63c to your computer and use it in GitHub Desktop.
RIP Post 12/7/2020
gg <- cces %>%
mutate(wev = case_when(race == 1 & pew_bornagain == 1 ~ 1, TRUE ~ 0)) %>%
group_by(year) %>%
mean_ci(wev, wt = weight, ci = .84) %>%
mutate(survey = "CCES")
gg2 <- gss %>%
filter(year >= 2008) %>%
mutate(white = case_when(race == 1 & hispanic == 1 ~ 1, TRUE ~ 0)) %>%
mutate(ba = case_when(reborn == 1 ~ 1, TRUE ~ 0)) %>%
mutate(wev = case_when(white == 1 & ba == 1 ~ 1, TRUE~ 0)) %>%
group_by(year) %>%
mean_ci(wev, wt = wtssall, ci = .84) %>%
mutate(survey = "GSS")
graph <- bind_rows(gg, gg2)
graph %>%
filter(year >= 2008) %>%
filter(year != 2017) %>%
filter(year != 2019) %>%
ggplot(., aes(x = factor(year), y= mean, fill = survey)) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
scale_fill_tron() +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = mean, pos = .02, sz = 4) +
labs(x = "", y = "", title = "Share of Americans Who Are White and Identify\nas Born-Again or Evangelical", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://evangelical_year_cces_white.png", type = "cairo-png", width = 7)
gg1 <- cces %>%
mutate(evan = case_when(pew_bornagain == 1 ~ 1, pew_bornagain == 2 ~ 0)) %>%
group_by(year) %>%
mean_ci(evan, wt = weight, ci = .84) %>%
mutate(survey = "CCES")
gg2 <- gss %>%
filter(year >= 2008) %>%
mutate(evan = case_when(reborn == 1 ~ 1, reborn == 2 ~ 0)) %>%
group_by(year) %>%
mean_ci(evan, wt = wtssall, ci = .84) %>%
mutate(survey = "GSS")
graph <- bind_rows(gg1, gg2)
graph %>%
filter(year >= 2008) %>%
filter(year != 2017) %>%
filter(year != 2019) %>%
ggplot(., aes(x = factor(year), y= mean, fill = survey)) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
scale_fill_npg() +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = mean, pos = .02, sz = 4.5) +
labs(x = "", y = "", title = "Share of Americans Who Identify as Born-Again or Evangelical", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://evangelical_year_cces_gss.png", type = "cairo-png", width = 7)
gg <- cces %>%
filter(year >= 2010) %>%
mutate(prot = case_when(religion == 1 ~ 1, TRUE ~ 0)) %>%
filter(pew_bornagain == 1) %>%
group_by(year) %>%
mean_ci(prot, wt = weight, ci = .84) %>%
mutate(survey = "CCES")
gg2 <- gss %>%
filter(year >= 2010) %>%
mutate(prot = case_when(relig == 1 ~ 1, TRUE ~ 0)) %>%
filter(reborn == 1) %>%
group_by(year) %>%
mean_ci(prot, wt = wtssall, ci = .84) %>%
mutate(survey = "GSS")
graph <- bind_rows(gg, gg2)
graph %>%
filter(year >= 2008) %>%
filter(year != 2017) %>%
filter(year != 2019) %>%
ggplot(., aes(x = factor(year), y= mean, fill = survey)) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
error_bar() +
scale_fill_npg() +
y_pct() +
lab_bar(top = FALSE, type = mean, pos = .03, sz = 5.5) +
labs(x = "", y = "", title = "Share of Born-Again/Evangelicals Who Identify as Protestants", caption = "@ryanburge\nData: CCES 2010-2019") +
ggsave("E://evangelical_year_cces_gss_prot.png", type = "cairo-png", width = 7)
graph <- cces %>%
filter(year == 2010 | year == 2019) %>%
group_by(year) %>%
filter(pew_bornagain == 1) %>%
mutate(trad = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 9 | religion == 10 | religion == 11 ~ "None",
TRUE ~ "Other Faith Group")) %>%
ct(trad, wt = weight)
graph %>%
ggplot(., aes(x = trad, y = pct, fill = factor(year))) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
scale_fill_d3() +
lab_bar(top = TRUE, type = pct, pos = .03, sz = 5) +
y_pct() +
labs(x = "", y = "", title= "Tradition Breakdown of Born-Again/Evangelicals", caption = "@ryanburge\nData: CCES 2010 + 2019") +
ggsave("E://ba_breakdown.png", type = "cairo-png", width = 6)
gg <- cces %>%
filter(protestant == 3) %>%
mutate(ev = case_when(pew_bornagain == 1 ~ 1, pew_bornagain == 2 ~ 0)) %>%
group_by(year) %>%
mean_ci(ev, wt = weight)
gg %>%
ggplot(., aes(x = factor(year), y= mean, fill = mean)) +
geom_col(color = "black") +
scale_fill_gradient(low = "#FFE47A", high = "#3D7EAA") +
error_bar() +
lab_bar(top = FALSE, type = mean, sz = 5, pos = .035) +
theme_rb() +
y_pct() +
labs(x = "", y = "", title = "Share of Non-Denoms Who ID as Evangelical", caption = "@ryanburge\nData: CCES 2008-2019") +
ggsave("E://nd_evans.png", type = "cairo-png", width = 7)
graph <- cces %>%
filter(year == 2010 | year == 2019) %>%
group_by(year) %>%
filter(pew_bornagain == 1) %>%
mutate(trad = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 9 | religion == 10 | religion == 11 ~ "None",
TRUE ~ "Other Faith Group")) %>%
ct(trad, wt = weight)
graph %>%
ggplot(., aes(x = trad, y = pct, fill = factor(year))) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
scale_fill_d3() +
lab_bar(top = TRUE, type = pct, pos = .03, sz = 5) +
y_pct() +
labs(x = "", y = "", title= "Tradition Breakdown of Self-Identified Evangelicals", caption = "@ryanburge\nData: CCES 2010 + 2019") +
ggsave("E://ba_breakdown.png", type = "cairo-png", width = 6)
graph <- cces %>%
filter(year == 2010 | year == 2019) %>%
mutate(ev = frcode(pew_bornagain == 1 ~ "Self ID Evangelicals",
pew_bornagain == 2 ~ "Not Self ID Evangelicals")) %>%
mutate(trad = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 9 | religion == 10 | religion == 11 ~ "None",
TRUE ~ "Other Faith Group")) %>%
mutate(rep = case_when(pid7 == 5 | pid7 == 6 | pid7 == 7 ~ 1,
pid7 <= 4 ~ 0)) %>%
group_by(year, ev, trad) %>%
mean_ci(rep, wt = weight) %>%
na.omit()
graph %>%
ggplot(., aes(x = trad, y = mean, fill = factor(year))) +
geom_col(color = "black", position = "dodge") +
theme_rb(legend = TRUE) +
scale_fill_d3() +
facet_wrap(~ ev) +
lab_bar(top = TRUE, type = mean, pos = .02, sz = 4) +
y_pct() +
labs(x = "", y = "", title= "Share Who Identify as Republicans", caption = "@ryanburge\nData: CCES 2010 + 2019") +
ggsave("E://ba_breakdown2.png", type = "cairo-png", width = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment