-
-
Save ryanburge/c5bf33413a4727188abe291e74d644cd to your computer and use it in GitHub Desktop.
This file contains 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 == 2022) %>% | |
cces_race(race) %>% | |
mutate(ev = case_when(pew_bornagain == 1 ~ 1, | |
pew_bornagain == 2 ~ 0)) %>% | |
group_by(race) %>% | |
mean_ci(ev, ci = .84) | |
gg %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = race, y = mean, fill = race)) + | |
geom_col(color = "black") + | |
theme_rb() + | |
error_bar() + | |
y_pct() + | |
scale_fill_manual(values = c(moma.colors("Panton", 5))) + | |
lab_bar(top = FALSE, type = lab, pos = .03, sz = 11) + | |
geom_text(aes(y = .03, label = ifelse(race == "Hispanic", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 11, family = "font", color = "white") + | |
geom_text(aes(y = .03, label = ifelse(race == "All Others", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 11, family = "font", color = "white") + | |
geom_text(aes(y = .03, label = ifelse(race == "Asian", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 11, family = "font", color = "white") + | |
labs(x = "Race", y = "", title = "Share Who Self-Identify as Evangelical by Race", caption = "@ryanburge\nData: Cooperative Election Study, 2022") | |
save("ev_race_ces22_new.png", wd = 5) | |
gg <- cces %>% | |
cces_race(race) %>% | |
mutate(ev = case_when(pew_bornagain == 1 ~ 1, | |
pew_bornagain == 2 ~ 0)) %>% | |
group_by(race, year) %>% | |
mean_ci(ev, ci = .84) | |
gg %>% | |
filter(year >= 2008) %>% | |
filter(race != "All Others") %>% | |
ggplot(., aes(x = year, y = mean, color = race, group = race)) + | |
geom_line() + | |
geom_point(stroke = 1, shape = 21, fill = "white") + | |
scale_color_manual(values = c(moma.colors("Panton", 4))) + | |
theme_rb() + | |
scale_y_continuous(labels = percent) + | |
add_text(x = 2013, y = .505, sz = 7, word = "Black") + | |
add_text(x = 2010, y = .325, sz = 7, word = "White") + | |
add_text(x = 2010, y = .275, sz = 7, word = "Hispanic") + | |
add_text(x = 2011, y = .21, sz = 7, word = "Asian") + | |
add_text(x = 2008, y = .51, sz = 7, word = "49%") + | |
add_text(x = 2008, y = .34, sz = 7, word = "33%") + | |
add_text(x = 2008, y = .275, sz = 7, word = "26%") + | |
add_text(x = 2008, y = .20, sz = 7, word = "18%") + | |
add_text(x = 2022, y = .46, sz = 7, word = "44%") + | |
add_text(x = 2022, y = .27, sz = 7, word = "25%") + | |
add_text(x = 2022, y = .23, sz = 7, word = "25%") + | |
add_text(x = 2022, y = .17, sz = 7, word = "15%") + | |
labs(x = "Year", y = "", title = "Share Who Self-Identify as Evangelical by Race", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022") | |
save("race_ev_year_ces22.png") | |
gg1 <- cces08 %>% | |
filter(V211 == 3) %>% | |
mutate(immstat = CC332) %>% | |
mutate(imm = frcode(immstat == 1 | immstat == 2 ~ "Immigrant", | |
immstat == 3 ~ "First Generation", | |
immstat == 4 ~ "Second Generation", | |
immstat == 5 ~ "Third Generation or More")) %>% | |
mutate(religpew = V219) %>% | |
mutate(relig = frcode(religpew == 1 ~ "Protestant", | |
religpew == 2 ~ "Catholic", | |
religpew >= 3 & religpew <= 8 ~ "Other World Religion", | |
religpew == 9 | religpew == 10 ~ "Atheist/Agnostic", | |
religpew == 11 ~ "Nothing in Particular")) %>% | |
group_by(imm) %>% | |
ct(relig, wt = V201, show_na = FALSE) %>% | |
mutate(year = "2008") | |
gg2 <- cces22 %>% | |
filter(race == 3) %>% | |
mutate(imm = frcode(immstat == 1 | immstat == 2 ~ "Immigrant", | |
immstat == 3 ~ "First Generation", | |
immstat == 4 ~ "Second Generation", | |
immstat == 5 ~ "Third Generation or More")) %>% | |
mutate(relig = frcode(religpew == 1 ~ "Protestant", | |
religpew == 2 ~ "Catholic", | |
religpew >= 3 & religpew <= 8 ~ "Other World Religion", | |
religpew == 9 | religpew == 10 ~ "Atheist/Agnostic", | |
religpew == 11 ~ "Nothing in Particular")) %>% | |
group_by(imm) %>% | |
ct(relig, wt = commonweight, show_na = FALSE) %>% | |
mutate(year = "2022") | |
graph <- bind_rows(gg1, gg2) %>% filter(imm != "NA") | |
graph %>% | |
mutate(lab = round(pct, 2)) %>% | |
ggplot(., aes(x = fct_rev(year), y = pct, fill = fct_rev(relig))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ imm, ncol =1, strip.position = "top") + | |
theme_rb() + | |
scale_fill_manual(values = c(moma.colors("OKeeffe", 5))) + | |
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 =11, family = "font", color = "black") + | |
geom_text(aes(label = ifelse(relig == "Protestant", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 11, family = "font", color = "white") + | |
# geom_text(aes(label = ifelse(age2 == "36-44", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, 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 Religious Composition of Hispanics by Immigrant Status", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022") | |
save("hisp_imm_stat.png", wd = 9, ht = 8) | |
gg1 <- cces08 %>% | |
filter(V211 == 3) %>% | |
mutate(immstat = CC332) %>% | |
mutate(ba = case_when(V215 == 1 ~ 1, | |
V215 == 2 ~ 0)) %>% | |
mutate(imm = frcode(immstat == 1 | immstat == 2 ~ "Immigrant", | |
immstat == 3 ~ "First Generation", | |
immstat == 4 ~ "Second Generation", | |
immstat == 5 ~ "Third Generation or More")) %>% | |
group_by(imm) %>% | |
mean_ci(ba, wt = V201, ci = .84) %>% | |
mutate(year = "2008") | |
gg2 <- cces22 %>% | |
filter(race == 3) %>% | |
mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
pew_bornagain == 2 ~ 0)) %>% | |
mutate(imm = frcode(immstat == 1 | immstat == 2 ~ "Immigrant", | |
immstat == 3 ~ "First Generation", | |
immstat == 4 ~ "Second Generation", | |
immstat == 5 ~ "Third Generation or More")) %>% | |
group_by(imm) %>% | |
mean_ci(ba, wt = commonweight, ci = .84) %>% | |
mutate(year = "2022") | |
graph <- bind_rows(gg1, gg2) %>% filter(imm != "NA") | |
graph %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = fct_rev(year), y = mean, fill = year)) + | |
geom_col(color = "black") + | |
facet_wrap(~ imm, ncol = 1) + | |
coord_flip() + | |
theme_rb() + | |
y_pct() + | |
scale_fill_calc() + | |
theme(plot.title = element_text(size = 16)) + | |
geom_text(aes(y = mean + .018, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 7, family = "font") + | |
labs(x = "",y = "", title = "Share of Hispanics Who Self-Identify as Evangelical by Immigrant Status", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022") | |
save("imm_ba_hispanic.png", wd = 7) | |
gg1 <- cces %>% | |
filter(race == 3) %>% | |
mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
pew_bornagain == 2 ~ 0)) %>% | |
filter(religion == 1) %>% | |
group_by(year) %>% | |
mean_ci(ba, ci = .84) %>% | |
mutate(type = "Protestants") | |
gg2 <- cces %>% | |
filter(race == 3) %>% | |
mutate(ba = case_when(pew_bornagain == 1 ~ 1, | |
pew_bornagain == 2 ~ 0)) %>% | |
filter(religion != 1) %>% | |
group_by(year) %>% | |
mean_ci(ba, ci = .84) %>% | |
mutate(type = "Non-Protestants") | |
both <- bind_rows(gg1, gg2) %>% filter(year >= 2008) | |
both %>% | |
ggplot(., aes(x = year, y = mean, fill = type, group = type, color = type)) + | |
geom_line() + | |
geom_point(stroke = 1, shape = 21, fill = "white") + | |
geom_smooth(se = FALSE, method = lm) + | |
scale_color_jama() + | |
theme_rb() + | |
scale_y_continuous(labels = percent) + | |
add_text(x = 2010, y = .76, word = "Protestants", sz = 6) + | |
add_text(x = 2012, y = .18, word = "Non-Protestants", sz = 6) + | |
labs(x = "Year", y = "", title = "Share of Hispanics Who Self-ID as Evangelical by Religion", caption = '@ryanburge\nData: Cooperative Election Study, 2008-2022') | |
save("ev_status_hisp_prot_nonprot.png", wd = 6) | |
cces22 %>% | |
cces_race(race) %>% | |
mutate(imm = frcode(immstat == 1 | immstat == 2 ~ "Immigrant", | |
immstat == 3 ~ "First Generation", | |
immstat == 4 ~ "Second Generation", | |
immstat == 5 ~ "Third Generation or More")) %>% | |
group_by(race) %>% | |
ct(imm, wt = commonweight, show_na = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment