Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
graph <- cces20 %>%
mutate(trad = frcode(evangelical == 1 & race == 1 ~ "White Evangelical",
evangelical == 1 & race != 1 ~ "Non-White Evangelical",
bprot == 1 ~ "Black Protestants",
mainline == 1 ~ "Mainline",
religpew == 2 & race == 1 ~ "White Catholic",
religpew == 2 & race != 1 ~ "Non-White 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",
TRUE ~ "Unclassified")) %>%
mutate(pid = frcode(pid7 == 1 | pid7 == 2 | pid7 == 3 ~ "Dem",
pid7 == 4 ~ "Ind",
pid7 == 5 | pid7 == 6 | pid7 == 7 ~ "Rep")) %>%
mutate(both = paste(trad, pid, sep = "-")) %>%
filter(pid != "NA") %>%
ct(both, wt = commonpostweight) %>%
arrange(-pct)
substrRight <- function(x, n){
substr(x, nchar(x)-n+1, nchar(x))
}
graph$pid <- substrRight(graph$both, 4)
graph$pid <- gsub("-", "", graph$pid)
graph$both <- gsub('.{4}$', '', graph$both)
sort <- graph %>%
group_by(both) %>%
summarise(sum = sum(n))
graph <- left_join(graph, sort)
graph <- graph %>%
mutate(pid = frcode(pid == "Dem" ~ "Democrat",
pid == "Ind" ~ "Independent",
pid == "Rep" ~ "Republican"))
graph %>%
ggplot(., aes(x = reorder(both, sum), y = pct, fill = pid)) +
geom_col(color = "black") +
coord_flip() +
y_pct() +
pid3_fill() +
theme_rb() +
theme(legend.position = c(.725, .125)) +
guides(fill = guide_legend(reverse=T)) +
geom_text(aes(label = ifelse(pct >.01, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "Share of the Entire Population", title = "What are the Largest Religious Voting Blocs in the United States?", caption = "@ryanburge\nData: CCES 2020") +
ggsave("E://voting_blocs_2020.png", type = "cairo-png", height = 6, width = 8)
gg <- cces20 %>%
filter(pew_bornagain == 1) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(ideo, wt = commonpostweight, show_na = FALSE) %>%
mutate(grp = "All Evangelicals")
gg1 <- cces20 %>%
filter(pew_bornagain == 1 & race == 1) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(ideo, wt = commonpostweight, show_na = FALSE) %>%
mutate(grp = "White Evangelicals")
gg2 <- cces20 %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(ideo, wt = commonpostweight, show_na = FALSE) %>%
mutate(grp = "Entire Sample")
gg3 <- cces20 %>%
filter(race == 1) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(ideo, wt = commonpostweight, show_na = FALSE) %>%
mutate(grp = "Entire White Sample")
graph <- bind_rows(gg, gg1, gg2, gg3)
graph %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(ideo))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ grp, 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 = 5, family = "font", color = "black") +
labs(x = "", y = "", title = "How Many Politically Liberal Evangelicals Are There in the United States?", subtitle = "", caption = "@ryanburge\nData: CES 2020") +
ggsave("E://ideo5_evangelical.png", width = 9, height = 3.75)
fun <- function(df, var, name){
aa1 <- df %>%
filter(pew_bornagain == 1) %>%
filter(ideo5 == 1 | ideo5 == 2) %>%
mutate(vv = {{var}}) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = commonweight, ci = .84) %>%
mutate(grp = "Liberal\nEvangelicals")
aa2 <- df %>%
filter(ideo5 == 1 | ideo5 == 2) %>%
mutate(vv = {{var}}) %>%
mutate(vv = case_when(vv == 1 ~ 1,
vv == 2 ~ 0)) %>%
mean_ci(vv, wt = commonweight, ci = .84) %>%
mutate(grp = "All\nLiberals")
bind_rows(aa1, aa2) %>% mutate(issue = name)
}
aaa1 <- cces20 %>% fun(CC20_331a, "Pathway to Citizenship")
aaa2 <- cces20 %>% fun(CC20_331b, "Increase Border Patrols")
aaa3 <- cces20 %>% fun(CC20_331c, "Withhold Funds\nfrom Sanctuary Cities")
aaa4 <- cces20 %>% fun(CC20_331d, "Cut Legal\nImmigration by 50%")
aaa5 <- cces20 %>% fun(CC20_331e, "Increase Border\nSecurity by $25B")
graph <- bind_df("aaa")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ issue) +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_tableau() +
lab_bar(top = FALSE, type = lab, pos = .07, sz = 6) +
labs(x = "", y = "", title = "Comparing Liberals on Immigration Policy", caption = '@ryanburge\nData: CES 2020') +
ggsave("E://imm_libs.png", type = "cairo-png", width = 6)
bbb1 <- cces20 %>% fun(CC20_327a, "Medicare for All")
bbb2 <- cces20 %>% fun(CC20_327b, "Allow Govt. to\nNegotiate Drug Prices")
bbb3 <- cces20 %>% fun(CC20_327c, "Lower Medicare\nAge to 50")
bbb4 <- cces20 %>% fun(CC20_327d, "Repeal the ACA")
bbb5 <- cces20 %>% fun(CC20_327e, "Restore the\nIndividual Mandate")
bbb6 <- cces20 %>% fun(CC20_327f, "Allow the Importation\nof Prescription Drugs")
graph <- bind_df("bbb")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ issue) +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_tableau() +
lab_bar(top = FALSE, type = lab, pos = .07, sz = 6) +
labs(x = "", y = "", title = "Comparing Liberals on Health Policy", caption = '@ryanburge\nData: CES 2020') +
ggsave("E://health_libs.png", type = "cairo-png", width = 6)
ccc1 <- cces20 %>% fun(CC20_330a, "Prohibit Govt. from\nPublishing Names/Addresses\nof Gun Owners")
ccc2 <- cces20 %>% fun(CC20_330b, "Ban Assault Rifles")
ccc3 <- cces20 %>% fun(CC20_330c, "Make it Easier\nto Obtain Concealed-Carry\nPermits")
graph <- bind_df("ccc")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ issue) +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_tableau() +
lab_bar(top = FALSE, type = lab, pos = .07, sz = 6) +
labs(x = "", y = "", title = "Comparing Liberals on Gun Policy", caption = '@ryanburge\nData: CES 2020') +
ggsave("E://guns_libs.png", type = "cairo-png", width = 6)
ddd1 <- cces20 %>% fun(CC20_332a, "Always Allow")
ddd2 <- cces20 %>% fun(CC20_332b, "Only For Rape,\nIncest, Life of Mother")
ddd3 <- cces20 %>% fun(CC20_332c, "Prohibit After\n20 Weeks")
ddd4 <- cces20 %>% fun(CC20_332d, "Allow Employers\nto Decline Abortion\nCoverage")
ddd5 <- cces20 %>% fun(CC20_332e, "Prohibit Federal\nFunds for Abortion")
ddd6 <- cces20 %>% fun(CC20_332f, "Make Completely\nIllegal")
ddd7 <- cces20 %>% fun(CC20_332g, "Prohibit States\nfrom Required\nAdmitting Privileges")
graph <- bind_df("ddd")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ issue, nrow = 2) +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_tableau() +
lab_bar(top = FALSE, type = lab, pos = .07, sz = 6) +
labs(x = "", y = "", title = "Comparing Liberals on Abortion Policy", caption = '@ryanburge\nData: CES 2020') +
ggsave("E://ab_libs.png", type = "cairo-png", width = 7)
eee1 <- cces20 %>% fun(CC20_355d, "Ban Transgender in the Military")
eee2 <- cces20 %>% fun(CC20_355e, "Require Able Bodied People to Work to Receive Food Stamps")
fff1 <- cces20 %>% fun(CC20_334b, "Require Police Body Cams")
fff2 <- cces20 %>% fun(CC20_334c, "Increase Police by 10%")
fff3 <- cces20 %>% fun(CC20_334d, "Decrease Police by 10%")
fff4 <- cces20 %>% fun(CC20_334e, "Ban Choke Holds")
fff5 <- cces20 %>% fun(CC20_334f, "Create Registry of\nCops w/Prior Misconduct")
fff6 <- cces20 %>% fun(CC20_334g, "End Military\nSurplus to Local PDs")
fff7 <- cces20 %>% fun(CC20_334h, "End Qualified Immunity")
graph <- bind_df("fff")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ issue, nrow = 2) +
theme_rb() +
y_pct() +
error_bar() +
scale_fill_tableau() +
lab_bar(top = FALSE, type = lab, pos = .07, sz = 6) +
labs(x = "", y = "", title = "Comparing Liberals on Policing Policy", caption = '@ryanburge\nData: CES 2020') +
ggsave("E://police_libs.png", type = "cairo-png", width = 7.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment