Skip to content

Instantly share code, notes, and snippets.

@ryanburge

ryanburge/black_catholics.R Secret

Last active Dec 27, 2020
Embed
What would you like to do?
Black Catholics
graph <- ns %>%
filter(religion == 2) %>%
mutate(race = frcode(race_ethnicity == 1 & hispanic == 1 ~ "White",
race_ethnicity == 2 ~ "Black",
hispanic >= 2 & hispanic <= 15 ~ "Hispanic",
race_ethnicity >= 4 & race_ethnicity <= 10 ~ "Asian", TRUE ~ "Something\nElse")) %>%
ct(race, wt = weight, show_na = FALSE)
graph %>%
ggplot(., aes(x = race, y = pct, fill = race)) +
geom_col(color = "black") +
theme_rb() +
y_pct() +
scale_fill_npg() +
lab_bar(top = TRUE, pos = .02, sz =5, type = pct) +
labs(x = "", y = "", title = "Racial Breakdown of Catholics", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://cath_race_breakdown.png", type = "cairo-png", width = 4)
graph <- ns %>%
mutate(xtn = case_when(religion == 1 | religion == 5 ~ 1, TRUE ~ 0)) %>%
mutate(white = case_when(race_ethnicity == 1 & hispanic == 1 ~ 1)) %>%
mutate(grp = frcode(white == 1 & religion == 2 ~ "White Catholic",
race_ethnicity == 2 & religion == 2 ~ "Black Catholic",
race_ethnicity >= 2 & race_ethnicity <= 15 & religion == 2 ~ "Hispanic Catholic",
race_ethnicity == 2 & xtn == 1 ~ "Black Protestant")) %>%
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.")) %>%
group_by(grp) %>%
ct(pid, show_na = FALSE, wt = weight)
graph %>%
filter(grp != "NA") %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ grp, 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 = "white") +
labs(x = "", y = "", title = "Partisan Distribution", subtitle = "", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://black_cath_pid7.png", width = 9, height = 3)
gg <- cces16 %>%
mutate(grp = frcode(race == 1 & religpew == 2 ~ "White Catholic",
race == 2 & religpew == 2 ~ "Black Catholic",
race == 3 & religpew == 2 ~ "Hispanic Catholic",
race == 2 & religpew == 1 ~ "Black Protestant")) %>%
group_by(grp) %>%
mutate(vote = frcode(CC16_410a == 1 ~ "Trump",
CC16_410a == 2 ~ "Clinton",
CC16_410a == 3 | CC16_410a == 4 | CC16_410a == 5 | CC16_410a == 8 ~ "Third Party")) %>%
ct(vote, wt= commonweight_vv_post, show_na = FALSE) %>%
na.omit()
gg %>%
filter(grp != "NA") %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ grp, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("darkorchid", "dodgerblue3", "firebrick3")) +
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 = "white") +
labs(x = "", y = "", title = "Presidential Vote in 2016", subtitle = "", caption = "@ryanburge\nData: CCES 2016") +
ggsave("E://black_cath_vote16.png", width = 9, height = 3)
graph <- ns %>%
mutate(male = case_when(gender == 2 ~ 1, gender == 1 ~ 0)) %>%
mutate(xtn = case_when(religion == 1 | religion == 5 ~ 1, TRUE ~ 0)) %>%
mutate(white = case_when(race_ethnicity == 1 & hispanic == 1 ~ 1)) %>%
mutate(grp = frcode(white == 1 & religion == 2 ~ "White Catholic",
race_ethnicity == 2 & religion == 2 ~ "Black Catholic",
race_ethnicity >= 2 & race_ethnicity <= 15 & religion == 2 ~ "Hispanic Catholic",
race_ethnicity == 2 & xtn == 1 ~ "Black Protestant")) %>%
mutate(coll = case_when(education >=8 ~ 1, education <= 7 ~ 0 )) %>%
group_by(grp) %>%
mean_ci(coll, wt = weight) %>%
na.omit()
graph %>%
ggplot(., aes(x = reorder(grp, mean), y = mean, fill = grp)) +
geom_col(color = 'black') +
coord_flip() +
y_pct() +
error_bar() +
theme_rb() +
scale_fill_npg() +
lab_bar(top = FALSE, type = mean, pos = .02, sz = 6) +
labs(x = "", y = "", title = "Share With a College Degree", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://coll_degree_black_cath.png", type = "cairo-png")
regg <- ns %>%
mutate(male = case_when(gender == 2 ~ 1, gender == 1 ~ 0)) %>%
mutate(xtn = case_when(religion == 1 | religion == 5 ~ 1, TRUE ~ 0)) %>%
mutate(white = case_when(race_ethnicity == 1 & hispanic == 1 ~ 1)) %>%
mutate(grp = frcode(white == 1 & religion == 2 ~ "White Catholic",
race_ethnicity == 2 & religion == 2 ~ "Black Catholic",
race_ethnicity >= 2 & race_ethnicity <= 15 & religion == 2 ~ "Hispanic Catholic",
race_ethnicity == 2 & xtn == 1 ~ "Black Protestant")) %>%
mutate(app = case_when(pres_approval == 1 | pres_approval == 2 ~ 1,
pres_approval == 3 | pres_approval == 4 ~ 0)) %>%
select(education, household_income, male, grp, white, app, age)
reg <- glm(app ~ education*grp + age + male + household_income, data = regg, family = "binomial")
graph <- interact_plot(reg, pred= education, modx = grp, int.width = .76, interval = TRUE)
graph +
theme_rb() +
scale_x_continuous(breaks = c(1,2,3,4,5,6,7,8,9,10,11), labels = c("","8th\nGrade", "", "HS Grad", "", "Some\nCollege", "", "4 Year", "", "Masters", "")) +
y_pct() +
add_text(x = 9, y = .55, word = "White Catholics", sz = 4) +
add_text(x = 9, y = .35, word = "Hispanic Catholics", sz = 4) +
add_text(x = 9, y = .27, word = "Black Catholics", sz = 4) +
add_text(x = 9, y = .18, word = "Black Protestants", sz = 4) +
labs(x = "Education", y = "Estimate of Trump's Approval", title = "Trump's Approval by Level of Education", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://black_cath_interact.png", type = "cairo-png", width = 7)
yyy1 <- gss %>%
filter(year < 2000) %>%
filter(catholic == 1) %>%
mutate(white = case_when(race == 1 ~ 1, TRUE ~ 0)) %>%
group_by(year) %>%
mean_ci(white, wt= wtssall)
yyy2 <- gss %>%
filter(year >= 2000) %>%
filter(catholic == 1) %>%
mutate(white = case_when(race == 1 & hispanic == 1 ~ 1, TRUE ~ 0)) %>%
group_by(year) %>%
mean_ci(white, wt= wtssall)
graph <- bind_rows(yyy1, yyy2)
graph %>%
ggplot(., aes(x = year, y = mean)) +
geom_point(size=3, color="white") +
geom_point(size=2, shape=1) +
geom_point(size=1, shape=19) +
geom_smooth(color = "darkorchid", linetype = "twodash", se = FALSE) +
theme_rb() +
y_pct() +
scale_x_continuous(breaks = c(1978, 1988, 1998, 2008, 2018)) +
labs(x = "", y = "", title = "Share of Catholics Who Are White", caption = "@ryanburge\nData: GSS 1972-2018") +
ggsave("E://white_catholics_gss.png", type = 'cairo-png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment