Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created April 4, 2024 17:00
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/08fe0e2bcc19bdfd6ba95e07af19b327 to your computer and use it in GitHub Desktop.
Save ryanburge/08fe0e2bcc19bdfd6ba95e07af19b327 to your computer and use it in GitHub Desktop.
aaa1 <- cces %>%
filter(race == 2) %>%
filter(religion == 1) %>%
filter(pew_attendance == 1 | pew_attendance == 2) %>%
filter(pid7 <= 7) %>%
group_by(year) %>%
mean_ci(pid7, wt = weight, ci = .84) %>%
select(year, pid = mean)
aaa2 <- cces %>%
filter(race == 2) %>%
filter(religion == 1) %>%
filter(pew_attendance == 1 | pew_attendance == 2) %>%
filter(ideo5 <= 5) %>%
group_by(year) %>%
mean_ci(ideo5, wt = weight, ci = .84) %>%
select(year, id = mean)
graph <- left_join(aaa1, aaa2) %>% mutate(year = as.factor(year)) %>% filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022)
library(ggrepel)
graph %>%
ggplot(., aes(x = pid, y = id, color = year, group = year)) +
geom_point() +
geom_text_repel(data = graph, aes(x = pid, y = id, label = year), family = "font", size = 8) +
scale_x_continuous(breaks = c(1,2,3,4,5,6,7), labels = c("Strong\nDem.", "Not Strong\nDemocrat", "Lean\nDemocrat", "Independent", "Lean\nRepublican", "Not Strong\nRepublican", "Strong\nRep."), limits = c(1, 7)) +
scale_y_continuous(breaks = c(1,2,3,4,5), labels = c("Very Liberal", "Liberal", "Moderate", "Conservative", "Very Conservative"), limits = c(1, 5)) +
scale_color_manual(values = c("#FF7F0E", "#1F77B4", "#2CA02C", "#D62728", "#9467BD")) +
theme_rb() +
labs(x = "Mean Political Partisanship", y = "Mean Political Ideology", title = "The Partisanship and Ideology of Weekly Attending Black Protestants", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022")
save("bprot_id_pid_scatter.png")
gg <- cces %>%
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022) %>%
filter(race == 2) %>%
filter(religion == 1) %>%
filter(pew_attendance == 1 | pew_attendance == 2) %>%
cces_pid7(pid7) %>%
group_by(year) %>%
ct(pid7, wt = weight, show_na = FALSE)
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid7))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1, strip.position = "left") +
theme_rb() +
pid7_fill() +
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 = 7, family = "font", color = "black") +
geom_text(aes(label = ifelse(pid7 == "Strong Dem.", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 7, family = "font", color = "white") +
geom_text(aes(label = ifelse(pct >.05 & pid7 == "Strong Rep.", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 7, 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 Political Partisanship of Black Protestants Who Attend Church Weekly", caption = "@ryanburge\nData: Cooperative Election Study, 2008-2022")
save("bprot_pid7.png", wd = 9, ht = 4)
ggg1 <- cces08 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(vote = CC410) %>%
mutate(vote = frcode(vote == 1 ~ "Republican",
vote == 2 ~ "Democrat",
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>%
ct(vote, wt = V201, show_na = FALSE) %>%
mutate(year = 2008)
ggg2 <- cces12 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(vote = CC410a) %>%
mutate(vote = frcode(vote == 1 ~ "Democrat",
vote == 2 ~ "Republican",
vote == 4 ~ "Third Party")) %>%
ct(vote, wt = weight_vv_post, show_na = FALSE) %>%
mutate(year = 2012)
ggg3 <- cces16 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(vote = CC16_410a) %>%
mutate(vote = frcode(vote == 1 ~ "Republican",
vote == 2 ~ "Democrat",
vote == 3 | vote == 4 | vote == 5 | vote == 8 ~ "Third Party")) %>%
ct(vote, wt = commonweight_vv_post, show_na = FALSE) %>%
mutate(year = 2016)
ggg4 <- cces20 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(vote = CC20_410) %>%
mutate(vote = frcode(vote == 1 ~ "Democrat",
vote == 2 ~ "Republican",
vote == 4 ~ "Third Party")) %>%
ct(vote, wt = commonpostweight, show_na = FALSE) %>%
mutate(year = 2020)
gg <- bind_rows(ggg1, ggg2, ggg3, ggg4)
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, 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 >.08, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8.5, family = "font", color = "black") +
labs(x = "", y = "", title = "Vote Choice Among Weekly Attending Black Protestants", subtitle = "", caption = "@ryanburge\nData: Cooperative Election Study 2008-2020")
save("bprot_wk_attend_vote.png", wd = 9, ht = 4)
cces <- read.fst("E://data/cces_abort21.fst")
ab22 <- cces22 %>%
cces_trad(religpew) %>%
mutate(age = 2022 - birthyr) %>%
select(trad2, pid3, pid7, race, age, income = faminc_new, educ, gender = gender4, weight = commonweight, pew_churatd, pew_bornagain, ab_choice = CC22_332a, ab_rape = CC22_332b, ab_late = CC22_332c, ab_ins = CC22_332d, ab_funds = CC22_332e, ab_never = CC22_332f) %>%
mutate(year = 2022)
cces <- bind_rows(cces, ab22)
yyy1 <- cces %>%
mutate(ab = case_when(ab_choice == 1 ~ 1,
ab_choice == 2 ~ 0)) %>%
filter(trad2 == "Black Protestant") %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
yyy2 <- cces %>%
mutate(ab = case_when(ab_choice == 1 ~ 1,
ab_choice == 2 ~ 0)) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "All Democrats")
graph1 <- bind_rows(yyy1, yyy2) %>%
mutate(sit = "Allow For Any Reason")
yyy1 <- cces %>%
mutate(ab = case_when(ab_funds == 1 ~ 1,
ab_funds == 2 ~ 0)) %>%
filter(trad2 == "Black Protestant") %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
yyy2 <- cces %>%
mutate(ab = case_when(ab_funds == 1 ~ 1,
ab_funds == 2 ~ 0)) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "All Democrats")
graph2 <- bind_rows(yyy1, yyy2) %>%
mutate(sit = "Prohibit Federal Funds")
yyy1 <- cces %>%
mutate(ab = case_when(ab_late == 1 ~ 1,
ab_late == 2 ~ 0)) %>%
filter(trad2 == "Black Protestant") %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
yyy2 <- cces %>%
mutate(ab = case_when(ab_late == 1 ~ 1,
ab_late == 2 ~ 0)) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "All Democrats")
graph3 <- bind_rows(yyy1, yyy2) %>%
mutate(sit = "Prohibit After 20 Weeks")
yyy1 <- cces %>%
mutate(ab = case_when(ab_never == 1 ~ 1,
ab_never == 2 ~ 0)) %>%
filter(trad2 == "Black Protestant") %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
yyy2 <- cces %>%
mutate(ab = case_when(ab_never == 1 ~ 1,
ab_never == 2 ~ 0)) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
group_by(year) %>%
mean_ci(ab, wt = weight, ci = .84) %>%
mutate(grp = "All Democrats")
graph4 <- bind_rows(yyy1, yyy2) %>%
mutate(sit = "Never Permit Abortion")
all <- bind_rows(graph1, graph2, graph3, graph4)
all %>%
ggplot(., aes(x = year, y = mean, color = grp, group = grp)) +
geom_point(stroke = .5, shape = 21, alpha = .45) +
geom_smooth(se = FALSE) +
facet_wrap(~ sit) +
theme_rb(legend = TRUE) +
scale_color_calc() +
scale_y_continuous(labels = percent) +
labs(x = "", y = "", title = "Views of Abortion Among Black Protestants and All Democrats", caption = "@ryanburge\nData: Cooperative Election Study, 2014-2022")
save("ab_dems_bprot.png", ht = 7, wd = 6.5)
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_331a == 1 ~ 1,
CC22_331a == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_331a == 1 ~ 1,
CC22_331a == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt1 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Pathway to Legal Status")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_331b == 1 ~ 1,
CC22_331b == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_331b == 1 ~ 1,
CC22_331b == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt2 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Increase Border Patrol Agents")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_331c == 1 ~ 1,
CC22_331c == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_331c == 1 ~ 1,
CC22_331c == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt3 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Reduce Legal Immigration by 50%")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_331d == 1 ~ 1,
CC22_331d == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_331d == 1 ~ 1,
CC22_331d == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt4 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Increased Border Funding by $25B")
graph <- bind_rows(tt1, tt2, tt3, tt4)
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ type, nrow = 1) +
theme_rb(legend = TRUE) +
scale_fill_calc() +
theme(axis.text.x = element_blank()) +
error_bar() +
scale_y_continuous(labels = percent) +
lab_bar(top = FALSE, type = lab, pos = .06, sz = 11) +
geom_text(aes(y = .06, label = ifelse(grp == "All Democrats", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 11, family = "font", color = "white") +
labs(x = "", y = "", title = "Views of Immigration Among All Democrats and Black Protestants", caption = "@ryanburge\nData: Cooperative Election Study, 2022")
save("immi_bprot_dems.png")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_334a == 1 ~ 1,
CC22_334a == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_334a == 1 ~ 1,
CC22_334a == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt1 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Eliminate Mandatory Minimums")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_334b == 1 ~ 1,
CC22_334b == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_334b == 1 ~ 1,
CC22_334b == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt2 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Require Body Cams for Police")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_334c == 1 ~ 1,
CC22_334c == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_334c == 1 ~ 1,
CC22_334c == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt3 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Increase Police by 10%")
aaa1 <- cces22 %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mutate(imm = case_when(CC22_334d == 1 ~ 1,
CC22_334d == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "Weekly Attending Black Protestants")
aaa2 <- cces22 %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mutate(imm = case_when(CC22_334d == 1 ~ 1,
CC22_334d == 2 ~ 0)) %>%
mean_ci(imm, wt = commonweight, ci = .84) %>%
mutate(grp = "All Democrats")
tt4 <- bind_rows(aaa1, aaa2) %>% mutate(type = "Decrease Police by 10%")
graph <- bind_rows(tt1, tt2, tt3, tt4)
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = grp, y = mean, fill = grp)) +
geom_col(color = "black") +
facet_wrap(~ type, nrow = 1) +
theme_rb(legend = TRUE) +
scale_fill_calc() +
theme(axis.text.x = element_blank()) +
error_bar() +
scale_y_continuous(labels = percent) +
lab_bar(top = FALSE, type = lab, pos = .06, sz = 11) +
geom_text(aes(y = .06, label = ifelse(grp == "All Democrats", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 11, family = "font", color = "white") +
labs(x = "", y = "", title = "Views of Police Among All Democrats and Black Protestants", caption = "@ryanburge\nData: Cooperative Election Study, 2022")
save("police_bprot_dems.png")
fun <- function(df, var1, var2, var3, weight, yr) {
aaa1 <- df %>%
filter({{var1}} <= 7) %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mean_ci({{var1}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Yourself")
aaa2 <- df %>%
filter({{var2}} <= 7) %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mean_ci({{var2}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Democrats")
aaa3 <- df %>%
filter({{var3}} <= 7) %>%
filter(race == 2) %>%
filter(religpew == 1) %>%
filter(pew_churatd == 1 | pew_churatd == 2) %>%
mean_ci({{var3}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Republicans")
bind_rows(aaa1, aaa2, aaa3)
}
yyy1 <- cces12 %>% fun(CC334A, CC334E, CC334F, weight_vv, yr = 2012)
yyy2 <- cces14 %>% fun(CC334A, CC334K, CC334L, weight, yr = 2014)
yyy3 <- cces16 %>% fun(CC16_340a, CC16_340g, CC16_340h, commonweight, yr = 2016)
yyy4 <- cces17 %>% fun(CC17_350a, CC17_350d, CC17_350e, weights_common, yr = 2017)
yyy5 <- cces18 %>% fun(CC18_334A, CC18_334D, CC18_334E, commonweight, yr = 2018)
yyy6 <- cces19 %>% fun(CC19_334a, CC19_334d, CC19_334e, commonweight, yr = 2019)
yyy7 <- cces20 %>% fun(CC20_340a, CC20_340e, CC20_340f, commonweight, yr = 2020)
yyy8 <- cces21 %>% fun(CC21_330a, CC21_330e, CC21_330f, commonweight, yr = 2021)
yyy9 <- cces22 %>% fun(CC22_340a, CC22_340e, CC22_340f, commonweight, yr = 2022)
qqq1 <- bind_df("yyy") %>% mutate(grp = "Weekly Attending Black Protestants")
fun <- function(df, var1, var2, var3, weight, yr) {
aaa1 <- df %>%
filter({{var1}} <= 7) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mean_ci({{var1}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Yourself")
aaa2 <- df %>%
filter({{var2}} <= 7) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mean_ci({{var2}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Democrats")
aaa3 <- df %>%
filter({{var3}} <= 7) %>%
filter(pid7 == 1 | pid7 == 2 | pid7 == 3) %>%
mean_ci({{var3}}, wt = {{weight}}) %>%
mutate(year = yr) %>%
mutate(type = "Republicans")
bind_rows(aaa1, aaa2, aaa3)
}
yyy1 <- cces12 %>% fun(CC334A, CC334E, CC334F, weight_vv, yr = 2012)
yyy2 <- cces14 %>% fun(CC334A, CC334K, CC334L, weight, yr = 2014)
yyy3 <- cces16 %>% fun(CC16_340a, CC16_340g, CC16_340h, commonweight, yr = 2016)
yyy4 <- cces17 %>% fun(CC17_350a, CC17_350d, CC17_350e, weights_common, yr = 2017)
yyy5 <- cces18 %>% fun(CC18_334A, CC18_334D, CC18_334E, commonweight, yr = 2018)
yyy6 <- cces19 %>% fun(CC19_334a, CC19_334d, CC19_334e, commonweight, yr = 2019)
yyy7 <- cces20 %>% fun(CC20_340a, CC20_340e, CC20_340f, commonweight, yr = 2020)
yyy8 <- cces21 %>% fun(CC21_330a, CC21_330e, CC21_330f, commonweight, yr = 2021)
yyy9 <- cces22 %>% fun(CC22_340a, CC22_340e, CC22_340f, commonweight, yr = 2022)
qqq2 <- bind_df("yyy") %>% mutate(grp = "All Democrats")
graph <- bind_rows(qqq1, qqq2)
graph$type <- factor(graph$type, levels = c("Democrats", "Yourself", "Republicans"))
graph %>%
mutate(year = as.factor(year)) %>%
ggplot(., aes(x = fct_rev(year), y = mean, color = type, group = type)) +
geom_hline(yintercept = 4, linetype = "twodash") +
geom_line() +
geom_errorbar(aes(ymin = lower, ymax=upper), size = 1, width = 0) +
geom_point(shape = 21, stroke = 2, fill = "white") +
coord_flip() +
facet_wrap(~ grp, ncol = 1) +
scale_y_continuous(breaks = c(1,2,3,4,5,6,7), labels = c("Very\nLiberal", "Lib.", "", "Middle of\nthe Road", "", "Cons.", "Very\nConservative")) +
scale_color_manual(values = c("dodgerblue3", "azure4", "firebrick3")) +
theme_rb(legend = TRUE) +
theme(strip.text = element_text(size = 20)) +
labs(x = "", y = "", title = "Place Yourself, Democrats, and Republicans in Ideological Space", caption = "@ryanburge\nData: Cooperative ELection Study, 2012-2022")
save("your_self_dems_republicans_bprot.png", ht = 9, wd = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment