Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created February 11, 2019 19:22
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/1a432fc5251217fdc67f07a24342bfed to your computer and use it in GitHub Desktop.
Save ryanburge/1a432fc5251217fdc67f07a24342bfed to your computer and use it in GitHub Desktop.
Catholics PID Changes 2018
### PID Ribbons White and Non-white ####
dd18 <- dfp %>%
filter(race ==1) %>%
filter(religpew ==2) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight_DFP, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2018) %>%
mutate(group = "White")
dd16 <- cces16 %>%
filter(race ==1) %>%
filter(religpew ==2) %>%
filter(pew_bornagain ==1) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = commonweight_vv, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2016) %>%
mutate(group = "White")
dd14 <- cces14 %>%
filter(race ==1) %>%
filter(religpew ==1) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2014) %>%
mutate(group = "White")
dd12 <- cces12 %>%
filter(race ==1) %>%
filter(religpew ==2) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight_vv, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2012) %>%
mutate(group = "White")
dd10 <- cces10 %>%
filter(V211 ==1) %>%
filter(V219 ==2) %>%
mutate(att = recode(V217, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
mutate(pid7 = case_when(CC421b == 1 ~ 3,
CC421b == 2 ~ 5,
CC421b == 3 ~ 4,
CC421_rep == 1 ~ 7,
CC421_rep == 2 ~ 6,
CC421_dem == 1 ~ 1,
CC421_dem == 2 ~ 2)) %>%
group_by(att) %>%
mean_ci(pid7, wt = V101, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2010) %>%
mutate(group = "White")
dd08 <- cces08 %>%
filter(V211 ==1) %>%
filter(V219 ==2) %>%
filter(CC307a <= 7) %>%
mutate(att = recode(V217, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(CC307a, wt = V201, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2008) %>%
mutate(group = "White")
dd18a <- dfp %>%
filter(race !=1) %>%
filter(religpew ==2) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight_DFP, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2018) %>%
mutate(group = "Non-White")
dd16a <- cces16 %>%
filter(race !=1) %>%
filter(religpew ==2) %>%
filter(pew_bornagain ==1) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = commonweight_vv, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2016) %>%
mutate(group = "Non-White")
dd14a <- cces14 %>%
filter(race !=1) %>%
filter(religpew ==1) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2014) %>%
mutate(group = "Non-White")
dd12a <- cces12 %>%
filter(race !=1) %>%
filter(religpew ==2) %>%
filter(pid7 <= 7) %>%
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(pid7, wt = weight_vv, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2012) %>%
mutate(group = "Non-White")
dd10a <- cces10 %>%
filter(V211 !=1) %>%
filter(V219 ==2) %>%
mutate(att = recode(V217, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
mutate(pid7 = case_when(CC421b == 1 ~ 3,
CC421b == 2 ~ 5,
CC421b == 3 ~ 4,
CC421_rep == 1 ~ 7,
CC421_rep == 2 ~ 6,
CC421_dem == 1 ~ 1,
CC421_dem == 2 ~ 2)) %>%
group_by(att) %>%
mean_ci(pid7, wt = V101, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2010) %>%
mutate(group = "Non-White")
dd08a <- cces08 %>%
filter(V211 !=1) %>%
filter(V219 ==2) %>%
filter(CC307a <= 7) %>%
mutate(att = recode(V217, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>%
group_by(att) %>%
mean_ci(CC307a, wt = V201, ci = .84) %>%
mutate(att = frcode(att == 1 ~ "Never",
att == 2 ~ "Seldom",
att == 3 ~ "Yearly",
att == 4 ~ "Monthly",
att == 5 ~ "Weekly",
att == 6 ~ "Weekly+",
att == 7 ~ "Don`t Know",
TRUE ~ "REMOVE")) %>%
mutate(year = 2008) %>%
mutate(group = "Non-White")
graph <- bind_df("dd") %>%
filter(att != "REMOVE") %>%
mutate(year = as.factor(year))
graph %>%
ggplot(., aes(x= att, y = mean, group = group, color = group)) +
geom_point() +
geom_line(size = 1) +
theme_gg("Abel") +
facet_wrap(~ year) +
geom_ribbon(aes(ymin=lower, ymax=upper, color = group, fill = group), alpha = .05, show.legend = FALSE) +
scale_fill_d3() +
scale_color_d3() +
scale_y_continuous(limits = c(1,7), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Strong Democrat", "Lean Democrat", "Independent", "Lean Republican", "Not Strong Republican", "Strong Republican")) +
labs(x ="Church Attendance", y = "Mean Party Identification", subtitle = "Among Catholics", title = "Catholic Partisanship at Each Attendance Level", caption = "Data: CCES (2012-2016) and Data for Progress (2018)") +
theme(legend.position = "bottom") +
theme(legend.title=element_blank()) +
theme(axis.text.x = element_text(size = 9)) +
ggsave("D://dfp/pid_ribbons_catholics.png", width = 10)
## Abortion by Race ####
abg <- cces16 %>%
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>%
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>%
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>%
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>%
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>%
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>%
filter(abort != "NA") %>%
filter(religpew ==2) %>%
mutate(race2 = car::recode(race, "1='White'; else ='Non-White '")) %>%
group_by(race2) %>%
ct(abort, wt = commonweight_vv)
g1 <- abg %>%
ggplot(.,aes(x = abort, y = pct, fill = race2)) +
geom_col(color = "black", position = "dodge") +
# facet_wrap(~ race2, ncol= 2) +
# scale_fill_manual(values = c("dodgerblue3", "azure3", "firebrick3")) +
theme_gg("Abel") +
scale_fill_d3() +
scale_y_continuous(labels = percent, limits = c(0, .400)) +
theme(legend.position = c(.5, .85)) +
theme(legend.direction = "horizontal") +
labs(x = "<- More Pro-Choice:More Pro-Life -->", y = "", title = "Distribution of Abortion Opinion by Race", subtitle = "Catholics", caption = "") +
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") +
ggsave("D://dfp/abort_catholic.png")
abg1 <- cces16 %>%
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>%
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>%
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>%
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>%
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>%
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>%
filter(abort != "NA") %>%
filter(evangelical ==1) %>%
mutate(race2 = car::recode(race, "1='White'; else ='Non-White '")) %>%
group_by(race2) %>%
ct(abort, wt = commonweight_vv)
g2 <- abg1 %>%
ggplot(.,aes(x = abort, y = pct, fill = race2)) +
geom_col(color = "black", position = "dodge") +
# facet_wrap(~ race2, ncol= 2) +
# scale_fill_manual(values = c("dodgerblue3", "azure3", "firebrick3")) +
theme_gg("Abel") +
scale_fill_d3() +
scale_y_continuous(labels = percent, limits = c(0, .400)) +
theme(legend.position = c(.5, .85)) +
theme(legend.direction = "horizontal") +
labs(x = "<- More Pro-Choice:More Pro-Life -->", y = "", title = "", subtitle = "Evangelicals", caption = "Data: CCES 2016") +
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") +
ggsave("D://dfp/abort_evangelical.png")
abg2 <- cces16 %>%
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>%
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>%
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>%
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>%
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>%
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>%
filter(abort != "NA") %>%
mutate(race2 = car::recode(race, "1='White'; else ='Non-White '")) %>%
group_by(race2) %>%
ct(abort, wt = commonweight_vv)
g3 <- abg2 %>%
ggplot(.,aes(x = abort, y = pct, fill = race2)) +
geom_col(color = "black", position = "dodge") +
# facet_wrap(~ race2, ncol= 2) +
# scale_fill_manual(values = c("dodgerblue3", "azure3", "firebrick3")) +
theme_gg("Abel") +
scale_fill_d3() +
scale_y_continuous(labels = percent, limits = c(0, .400)) +
theme(legend.position = c(.5, .85)) +
theme(legend.direction = "horizontal") +
labs(x = "<- More Pro-Choice:More Pro-Life -->", y = "", title = "", subtitle = "Entire Sample", caption = "") +
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") +
ggsave("D://dfp/abort_all.png")
abg3 <- cces16 %>%
mutate(ab1 = recode(CC16_332a, "2=1; 1=0; else = NA")) %>%
mutate(ab2 = recode(CC16_332c, "1=1; 2=0; else = NA")) %>%
mutate(ab3 = recode(CC16_332d, "1=1; 2=0; else = NA")) %>%
mutate(ab4 = recode(CC16_332e, "1=1; 2=0; else = NA")) %>%
mutate(ab5 = recode(CC16_332f, "1=1; 2=0; else = NA")) %>%
mutate(abort = ab1 + ab2 + ab3 + ab4 + ab5) %>%
filter(abort != "NA") %>%
filter(none ==1) %>%
mutate(race2 = car::recode(race, "1='White'; else ='Non-White '")) %>%
group_by(race2) %>%
ct(abort, wt = commonweight_vv)
g4 <- abg3 %>%
ggplot(.,aes(x = abort, y = pct, fill = race2)) +
geom_col(color = "black", position = "dodge") +
# facet_wrap(~ race2, ncol= 2) +
# scale_fill_manual(values = c("dodgerblue3", "azure3", "firebrick3")) +
theme_gg("Abel") +
scale_fill_d3() +
scale_y_continuous(labels = percent, limits = c(0, .400)) +
theme(legend.position = c(.5, .85)) +
theme(legend.direction = "horizontal") +
labs(x = "<- More Pro-Choice:More Pro-Life -->", y = "", title = "", subtitle = "Nones", caption = "") +
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") +
ggsave("D://dfp/abort_nones.png")
both <- g1 + g3 + g4 + g2 + plot_layout(ncol =2)
ggsave("D://dfp/abort_four_patches.png", both, width = 10, height = 8)
### Approve of Trump ###
heat <- dfp %>%
# filter(race ==1) %>%
filter(religpew ==2) %>%
mutate(att = frcode(pew_churatd == 6 ~ "Never",
pew_churatd == 5 ~ "Seldom",
pew_churatd == 4 ~ "Yearly",
pew_churatd == 3 ~ "Monthly",
pew_churatd == 2 ~ "Weekly",
pew_churatd == 1 ~ "Weekly+")) %>%
filter(app_dtrmp <= 4) %>%
mutate(tr = frcode(app_dtrmp == 4 ~ "Strongly Disapprove",
app_dtrmp == 3 ~ "Somewhat Disapprove",
app_dtrmp == 2 ~ "Somewhat Approve",
app_dtrmp == 1 ~ "Strongly Approve")) %>%
select(att, tr) %>%
group_by(att) %>%
ct(tr) %>%
ungroup(att)
heat %>%
filter(att != "NA") %>%
ggplot(., aes(x= att, y = tr)) +
geom_tile(aes(fill = pct), color = "black") +
scale_fill_gradient(low = "azure3", high = "#E94057") +
theme_gg("Abel") +
geom_text(aes(x= att, y = tr, label = paste0(pct*100, '%')), size = 4, family = "font") +
labs(x= "", y = "", title = "Job Approval for President Trump", subtitle = "Among Catholics", caption = "Data: Data for Progress (2018)") +
ggsave("D://dfp/heatmap_catholic.png", width = 6)
### Favorability Graph ####
## Favorability Graph ####
favor_fun <- function(df, var, var1){
var <- enquo(var)
df1 <- df %>%
filter(religpew ==2) %>%
filter(pew_bornagain ==1) %>%
filter(!! var <= 4) %>%
mutate(ques = recode(!! var, "1=4; 2=3; 3=2; 4=1")) %>%
mean_ci(ques, wt = weight_DFP, ci = .84) %>%
mutate(group = var1) %>%
mutate(sample = "Catholics")
df2 <- df %>%
filter(!! var <= 4) %>%
mutate(ques = recode(!! var, "1=4; 2=3; 3=2; 4=1")) %>%
mean_ci(ques, wt = weight_DFP, ci = .84) %>%
mutate(group = var1) %>%
mutate(sample = "Entire Sample")
df3 <- df %>%
filter(pid3 ==3) %>%
filter(!! var <= 4) %>%
mutate(ques = recode(!! var, "1=4; 2=3; 3=2; 4=1")) %>%
mean_ci(ques, wt = weight_DFP, ci = .84) %>%
mutate(group = var1) %>%
mutate(sample = "Independents")
bind_rows(df1, df2, df3)
}
eee1 <- dfp %>% favor_fun(favor_labor, "Labor Unions")
eee2 <- dfp %>% favor_fun(favor_dem, "Democratic Party")
eee3 <- dfp %>% favor_fun(favor_rep, "Republican Party")
eee4 <- dfp %>% favor_fun(favor_aca, "Obamacare/ACA")
eee5 <- dfp %>% favor_fun(favor_dtrump, "Trump")
eee6 <- dfp %>% favor_fun(favor_mcconnell, "McConnell")
eee7 <- dfp %>% favor_fun(favor_demcong, "Dem. in Congress")
eee8 <- dfp %>% favor_fun(favor_repcong, "Rep. in Congress")
eee9 <- dfp %>% favor_fun(favor_metoo, "MeToo")
eee10 <- dfp %>% favor_fun(favor_blm, "Black Lives Matter")
graph <- bind_df("eee")
graph %>%
ggplot(., aes(y=mean, x= fct_reorder(group, mean), color = sample)) +
geom_point(position=position_dodge(width=0.5), size =4) +
geom_errorbar(aes(ymin = lower, ymax=upper), position=position_dodge(0.5), size = 1) +
coord_flip() +
theme_gg("Abel") +
labs(title = "Favorability of Various Groups", x = "", y = "Level of Favorability", caption = "Data: Data for Progress (2018)") +
scale_y_continuous(limits = c(0.85,4.05), breaks = c(1,2,3,4), labels = c("Very Unfavorable", "Somewhat Unfavorable", "Somewhat Favorable", "Very Favorable")) +
scale_color_npg() +
theme(legend.position = "bottom") +
theme(legend.title=element_blank()) +
theme(text=element_text(size=28, family="font")) +
ggsave("D://dfp/group_like_catholics.png", height = 8, width =16)
## Vote Choice in 2016 ####
gg1 <- cces16 %>%
filter(religpew ==2) %>%
filter(race ==1) %>%
filter(CC16_410a <= 2) %>%
ct(CC16_410a, wt = commonweight_vv_post) %>%
mutate(vote16 = frcode(CC16_410a ==1 ~ "Trump",
CC16_410a ==2 ~ "Clinton",
CC16_410a ==3 ~ "Johnson",
CC16_410a ==4 ~ "Stein"))
bar1 <- gg1 %>%
ggplot(., aes(x =1, y = pct, fill = vote16)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_manual(values = c("firebrick3", "dodgerblue3")) +
theme_gg("Abel") +
theme(legend.position = "none") +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank())+
scale_y_continuous(labels = percent) +
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 6, family = "font") +
annotate("text", x= .75, y = .203, label = "Clinton", size = 6, family = "font") +
annotate("text", x= .75, y = .703, label = "Trump", size = 6, family = "font") +
labs(x = "", y = "", title = "White Catholic Vote Choice in 2016", caption = "Data: CCES 2016") +
ggsave("D://dfp/catholic16vote.png", height = 2)
gg2 <- dfp %>%
filter(religpew ==2) %>%
filter(race ==1) %>%
filter(djtrelct !=3) %>%
ct(djtrelct, wt = weight_DFP) %>%
mutate(vote20 = frcode(djtrelct ==1 ~ "Yes",
djtrelct ==2 ~ "No",
djtrelct ==3 ~ "Not Sure"))
bar2 <- gg2 %>%
ggplot(., aes(x =1, y = pct, fill = vote20)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_manual(values = c("firebrick3", "dodgerblue3", "azure3")) +
theme_gg("Abel") +
theme(legend.position = "none") +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank())+
scale_y_continuous(labels = percent) +
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 6, family = "font") +
annotate("text", x= .75, y = .196, label = "No", size = 6, family = "font") +
annotate("text", x= .75, y = .696, label = "Yes", size = 6, family = "font") +
labs(x = "", y = "", title = "Would You Vote to Re-elect Trump in 2020? (Among White Catholics)", caption = "Data: Data for Progress (2018)") +
ggsave("D://dfp/catholic20vote.png", height = 2)
both <- bar1 + bar2 + plot_layout(ncol =1)
ggsave("D://dfp/vote16_20_white.png", both)
gg1 <- cces16 %>%
filter(religpew ==2) %>%
filter(race !=1) %>%
filter(CC16_410a <= 2) %>%
ct(CC16_410a, wt = commonweight_vv_post) %>%
mutate(vote16 = frcode(CC16_410a ==1 ~ "Trump",
CC16_410a ==2 ~ "Clinton",
CC16_410a ==3 ~ "Johnson",
CC16_410a ==4 ~ "Stein"))
bar1 <- gg1 %>%
ggplot(., aes(x =1, y = pct, fill = vote16)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_manual(values = c("firebrick3", "dodgerblue3")) +
theme_gg("Abel") +
theme(legend.position = "none") +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank())+
scale_y_continuous(labels = percent) +
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 6, family = "font") +
annotate("text", x= .75, y = .363, label = "Clinton", size = 6, family = "font") +
annotate("text", x= .75, y = .863, label = "Trump", size = 6, family = "font") +
labs(x = "", y = "", title = "Non-White Catholic Vote Choice in 2016", caption = "Data: CCES 2016") +
ggsave("D://dfp/catholic16vote_poc.png", height = 2)
gg2 <- dfp %>%
filter(religpew ==2) %>%
filter(race !=1) %>%
filter(djtrelct !=3) %>%
ct(djtrelct, wt = weight_DFP) %>%
mutate(vote20 = frcode(djtrelct ==1 ~ "Yes",
djtrelct ==2 ~ "No",
djtrelct ==3 ~ "Not Sure"))
bar2 <- gg2 %>%
ggplot(., aes(x =1, y = pct, fill = vote20)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_manual(values = c("firebrick3", "dodgerblue3", "azure3")) +
theme_gg("Abel") +
theme(legend.position = "none") +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank())+
scale_y_continuous(labels = percent) +
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 6, family = "font") +
annotate("text", x= .75, y = .33, label = "No", size = 6, family = "font") +
annotate("text", x= .75, y = .83, label = "Yes", size = 6, family = "font") +
labs(x = "", y = "", title = "Would You Vote to Re-elect Trump in 2020? (Among Non-White Catholics)", caption = "Data: Data for Progress (2018)") +
ggsave("D://dfp/catholic20vote_poc.png", height = 2)
both <- bar1 + bar2 + plot_layout(ncol =1)
ggsave("D://dfp/vote16_20_poc.png", both)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment