Last active
January 18, 2019 22:53
-
-
Save ryanburge/a6e30eed9abe21eed98eac5f7acd6836 to your computer and use it in GitHub Desktop.
Primary Voters to General Election
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
## First Graph #### | |
aaa <- cces08 %>% | |
mutate(att = recode(V217, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>% | |
mutate(vote = recode(CC410, "3:9 = NA")) %>% | |
filter(vote != "NA") %>% | |
filter(evangelical ==1) %>% | |
filter(V211 ==1) %>% | |
group_by(att) %>% | |
ct(vote, wt = V201) %>% | |
mutate(year = 2008) | |
aaa1 <- cces12 %>% | |
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>% | |
mutate(vote = recode(CC410a, "1=2; 2=1; 3:9 = NA")) %>% | |
filter(vote != "NA") %>% | |
filter(evangelical ==1) %>% | |
filter(race ==1) %>% | |
group_by(att) %>% | |
ct(vote, wt = V103) %>% | |
mutate(year = 2012) | |
aaa2 <- cces16 %>% | |
mutate(att = recode(pew_churatd, "1=6; 2=5; 3=4; 4=3; 5=2; 6=1; else = NA")) %>% | |
mutate(vote = recode(CC16_410a, "3:99 = NA")) %>% | |
filter(vote != "NA") %>% | |
filter(evangelical ==1) %>% | |
filter(race ==1) %>% | |
group_by(att) %>% | |
ct(vote, wt = commonweight_vv_post) %>% | |
mutate(year = 2016) | |
graph <- bind_df("aaa") %>% | |
filter(att != "NA") %>% | |
ungroup(att) %>% | |
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")) | |
graph %>% | |
mutate(vote = recode(vote, "1=2; 2=1")) %>% | |
ggplot(., aes(x=att, y = pct, fill = factor(vote))) + | |
geom_col(color = "black") + | |
facet_wrap(~ year) + | |
theme_gg("Abel") + | |
scale_y_continuous(labels = percent) + | |
scale_fill_manual(values = c("dodgerblue3","firebrick3")) + | |
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 14, family = "font") + | |
labs(x = "", y = "Share of Two Party Vote", title = "White Evangelicals Votes Choice", caption = "Data: CCES 2008-2016") + | |
ggsave("D://cces/images/vote_3waves.png", width = 10) | |
### Making Vote Choice Bar Graphs #### | |
graph <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pew_churatd_2016 < 7) %>% | |
group_by(pew_churatd_2016) %>% | |
filter(pp_repprim16_2016 <= 5) %>% | |
ct(pp_repprim16_2016, wt = weight_2016) %>% | |
ungroup(pew_churatd_2016) %>% | |
mutate(att = frcode(pew_churatd_2016 == 6 ~ "Never", | |
pew_churatd_2016 == 5 ~ "Seldom", | |
pew_churatd_2016 == 4 ~ "Yearly", | |
pew_churatd_2016 == 3 ~ "Monthly", | |
pew_churatd_2016 == 2 ~ "Weekly", | |
pew_churatd_2016 == 1 ~ "Weekly+")) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ")) | |
graph %>% | |
na.omit() %>% | |
ggplot(., aes(x = att, y = pct, fill = fct_rev(cand))) + | |
geom_col(color = "black", position = "dodge") + | |
scale_fill_lancet() + | |
scale_y_continuous(labels = percent) + | |
theme_gg("Abel") + | |
labs(x = "", y = "", title ="White Evangelicals Primary Vote Choice", caption = "Voter Study Group 2016") + | |
theme(legend.position = "bottom") + | |
geom_text(aes(y = pct + .025, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 10, family = "font") + | |
ggsave("D://cces/images/vp_cand.png", width = 12) | |
## This is for White Born Agains #### | |
graph <- vp %>% | |
filter(pew_bornagain_2016 ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pew_churatd_2016 < 7) %>% | |
group_by(pew_churatd_2016) %>% | |
filter(pp_repprim16_2016 <= 5) %>% | |
ct(pp_repprim16_2016, wt = weight_2016) %>% | |
ungroup(pew_churatd_2016) %>% | |
mutate(att = frcode(pew_churatd_2016 == 6 ~ "Never", | |
pew_churatd_2016 == 5 ~ "Seldom", | |
pew_churatd_2016 == 4 ~ "Yearly", | |
pew_churatd_2016 == 3 ~ "Monthly", | |
pew_churatd_2016 == 2 ~ "Weekly", | |
pew_churatd_2016 == 1 ~ "Weekly+")) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ")) | |
graph %>% | |
na.omit() %>% | |
ggplot(., aes(x = att, y = pct, fill = fct_rev(cand))) + | |
geom_col(color = "black", position = "dodge") + | |
scale_fill_lancet() + | |
scale_y_continuous(labels = percent) + | |
theme_gg("Abel") + | |
labs(x = "", y = "", title ="White Born Agains Primary Vote Choice", caption = "Voter Study Group 2016") + | |
theme(legend.position = "bottom") + | |
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 10, family = "font") + | |
ggsave("D://cces/images/vp_cand_ba.png", width = 10) | |
## Catholic Rep Primary #### | |
graph <- vp %>% | |
filter(religpew_2016 ==2) %>% | |
filter(pew_churatd_2016 < 7) %>% | |
group_by(pew_churatd_2016) %>% | |
filter(pp_repprim16_2016 <= 5) %>% | |
ct(pp_repprim16_2016, wt = weight_2016) %>% | |
ungroup(pew_churatd_2016) %>% | |
mutate(att = frcode(pew_churatd_2016 == 6 ~ "Never", | |
pew_churatd_2016 == 5 ~ "Seldom", | |
pew_churatd_2016 == 4 ~ "Yearly", | |
pew_churatd_2016 == 3 ~ "Monthly", | |
pew_churatd_2016 == 2 ~ "Weekly", | |
pew_churatd_2016 == 1 ~ "Weekly+")) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ")) | |
graph %>% | |
na.omit() %>% | |
ggplot(., aes(x = att, y = pct, fill = fct_rev(cand))) + | |
geom_col(color = "black", position = "dodge") + | |
scale_fill_lancet() + | |
scale_y_continuous(labels = percent) + | |
theme_gg("Abel") + | |
labs(x = "", y = "", title ="Catholics Republican Primary Vote Choice", caption = "Voter Study Group 2016") + | |
theme(legend.position = "bottom") + | |
geom_text(aes(y = pct + .025, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 10, family = "font") + | |
ggsave("D://cces/images/vp_cand_cath.png", width = 12) | |
## ProLife White Evangelicals Vote Choice #### | |
graph <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(abortview3_2016 ==3) %>% | |
# filter(gaymar_2016 ==2) %>% | |
filter(pew_churatd_2016 < 7) %>% | |
group_by(pew_churatd_2016) %>% | |
filter(pp_repprim16_2016 <= 5) %>% | |
ct(pp_repprim16_2016, wt = weight_2016) %>% | |
ungroup(pew_churatd_2016) %>% | |
mutate(att = frcode(pew_churatd_2016 == 6 ~ "Never", | |
pew_churatd_2016 == 5 ~ "Seldom", | |
pew_churatd_2016 == 4 ~ "Yearly", | |
pew_churatd_2016 == 3 ~ "Monthly", | |
pew_churatd_2016 == 2 ~ "Weekly", | |
pew_churatd_2016 == 1 ~ "Weekly+")) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ")) | |
graph %>% | |
na.omit() %>% | |
ggplot(., aes(x = att, y = pct, fill = fct_rev(cand))) + | |
geom_col(color = "black", position = "dodge") + | |
scale_fill_lancet() + | |
scale_y_continuous(labels = percent) + | |
theme_gg("Abel") + | |
labs(x = "", y = "", title ="White Pro-Life Evangelicals Primary Vote Choice", caption = "Voter Study Group 2016") + | |
theme(legend.position = "bottom") + | |
geom_text(aes(y = pct + .025, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 10, family = "font") + | |
ggsave("D://cces/images/vp_cand_prolife_evan.png", width = 12) | |
## Issue Importance by Vote Choice #### | |
imp_fun <- function(df, var, var1){ | |
var <- enquo(var) | |
df %>% | |
mutate(issue = recode(!! var, "1=4;2=3;3=2;4=1; else = NA")) %>% | |
filter(pp_repprim16_2016 <= 4) %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
group_by(pp_repprim16_2016) %>% | |
mean_ci(issue) %>% | |
mutate(issue = var1) %>% | |
ungroup(pp_repprim16_2016) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ")) | |
} | |
ddd <- vp %>% imp_fun(imiss_a_2016, "Crime") | |
ddd1 <- vp %>% imp_fun(imiss_b_2016, "Economy") | |
ddd2 <- vp %>% imp_fun(imiss_c_2016, "Immigration") | |
ddd3 <- vp %>% imp_fun(imiss_d_2016, "Environment") | |
ddd5 <- vp %>% imp_fun(imiss_e_2016, "Religious liberty") | |
ddd6 <- vp %>% imp_fun(imiss_f_2016, "Terrorism") | |
ddd7 <- vp %>% imp_fun(imiss_g_2016, "Gay rights") | |
ddd8 <- vp %>% imp_fun(imiss_h_2016, "Education") | |
ddd9 <- vp %>% imp_fun(imiss_i_2016, "Family Leave") | |
ddd10 <- vp %>% imp_fun(imiss_j_2016, "Health Care") | |
ddd11 <- vp %>% imp_fun(imiss_k_2016, "Money in Politics") | |
ddd12 <- vp %>% imp_fun(imiss_l_2016, "Climate Change") | |
ddd13 <- vp %>% imp_fun(imiss_m_2016, "Social Security") | |
ddd14 <- vp %>% imp_fun(imiss_n_2016, "Infrastructure") | |
ddd15 <- vp %>% imp_fun(imiss_o_2016, "Jobs") | |
ddd16 <- vp %>% imp_fun(imiss_p_2016, "Budget Deficit") | |
ddd17 <- vp %>% imp_fun(imiss_q_2016, "Poverty") | |
ddd18 <- vp %>% imp_fun(imiss_r_2016, "Taxes") | |
ddd19 <- vp %>% imp_fun(imiss_s_2016, "Medicare") | |
ddd20 <- vp %>% imp_fun(imiss_t_2016, "Abortion") | |
ddd21 <- vp %>% imp_fun(imiss_u_2016, "Size of Govt.") | |
ddd22 <- vp %>% imp_fun(imiss_x_2016, "Racial Equality") | |
ddd23 <- vp %>% imp_fun(imiss_y_2016, "Gender Equality") | |
graph <- bind_df("ddd") | |
graph %>% | |
filter(cand != " Rubio ") %>% | |
ggplot(., aes(y=mean, x= fct_reorder(issue, mean), color = cand)) + | |
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 = "Issue Importance Among White Evangelicals", x = "Issue Area", y = "Level of Importance", caption = "Data: Voter Study Group 2016") + | |
scale_y_continuous(limits = c(0.85,5.05), breaks = c(1,2,3,4,5), labels = c("No Importance", "Very Low", "Somewhat Low", "Somewhat High", "Very High")) + | |
scale_color_npg() + | |
theme(legend.position = "bottom") + | |
theme(legend.title=element_blank()) + | |
theme(text=element_text(size=64, family="font")) + | |
ggsave("D://cces/images/voter_imp_vp.png", height = 10, width =12) | |
### Issue Importance by Attendance #### | |
imp_fun <- function(df, var, var1){ | |
var <- enquo(var) | |
df %>% | |
mutate(issue = recode(!! var, "1=4;2=3;3=2;4=1; else = NA")) %>% | |
filter(pew_churatd_2016 < 7) %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
group_by(pew_churatd_2016) %>% | |
mean_ci(issue) %>% | |
mutate(issue = var1) %>% | |
ungroup(pew_churatd_2016) %>% | |
mutate(att = frcode(pew_churatd_2016 == 6 ~ "Never", | |
pew_churatd_2016 == 5 ~ "Seldom", | |
pew_churatd_2016 == 4 ~ "Yearly", | |
pew_churatd_2016 == 3 ~ "Monthly", | |
pew_churatd_2016 == 2 ~ "Weekly", | |
pew_churatd_2016 == 1 ~ "Weekly+")) | |
} | |
ddd <- vp %>% imp_fun(imiss_a_2016, "Crime") | |
ddd1 <- vp %>% imp_fun(imiss_b_2016, "Economy") | |
ddd2 <- vp %>% imp_fun(imiss_c_2016, "Immigration") | |
ddd3 <- vp %>% imp_fun(imiss_d_2016, "Environment") | |
ddd5 <- vp %>% imp_fun(imiss_e_2016, "Religious liberty") | |
ddd6 <- vp %>% imp_fun(imiss_f_2016, "Terrorism") | |
ddd7 <- vp %>% imp_fun(imiss_g_2016, "Gay rights") | |
ddd8 <- vp %>% imp_fun(imiss_h_2016, "Education") | |
ddd9 <- vp %>% imp_fun(imiss_i_2016, "Family Leave") | |
ddd10 <- vp %>% imp_fun(imiss_j_2016, "Health Care") | |
ddd11 <- vp %>% imp_fun(imiss_k_2016, "Money in Politics") | |
ddd12 <- vp %>% imp_fun(imiss_l_2016, "Climate Change") | |
ddd13 <- vp %>% imp_fun(imiss_m_2016, "Social Security") | |
ddd14 <- vp %>% imp_fun(imiss_n_2016, "Infrastructure") | |
ddd15 <- vp %>% imp_fun(imiss_o_2016, "Jobs") | |
ddd16 <- vp %>% imp_fun(imiss_p_2016, "Budget Deficit") | |
ddd17 <- vp %>% imp_fun(imiss_q_2016, "Poverty") | |
ddd18 <- vp %>% imp_fun(imiss_r_2016, "Taxes") | |
ddd19 <- vp %>% imp_fun(imiss_s_2016, "Medicare") | |
ddd20 <- vp %>% imp_fun(imiss_t_2016, "Abortion") | |
ddd21 <- vp %>% imp_fun(imiss_u_2016, "Size of Govt.") | |
ddd22 <- vp %>% imp_fun(imiss_x_2016, "Racial Equality") | |
ddd23 <- vp %>% imp_fun(imiss_y_2016, "Gender Equality") | |
graph <- bind_df("ddd") | |
graph %>% | |
# filter(cand != " Rubio ") %>% | |
ggplot(., aes(y=mean, x= fct_reorder(issue, mean), color = att)) + | |
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 = "Issue Importance Among White Evangelicals", x = "Issue Area", y = "Level of Importance", caption = "Data: Voter Study Group 2016") + | |
scale_y_continuous(limits = c(0.85,5.05), breaks = c(1,2,3,4,5), labels = c("No Importance", "Very Low", "Somewhat Low", "Somewhat High", "Very High")) + | |
scale_color_npg() + | |
theme(legend.position = "bottom") + | |
theme(legend.title=element_blank()) + | |
theme(text=element_text(size=64, family="font")) + | |
ggsave("D://cces/images/voter_imp_vp_att.png", height = 10, width =12) | |
eee <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pp_repprim16_2016 ==3) %>% | |
filter(presvote16post_2016 <= 3) %>% | |
ct(presvote16post_2016, wt = weight_2017) %>% | |
mutate(vote = frcode(presvote16post_2016 == 1 ~ "Clinton", | |
presvote16post_2016 == 2 ~ "Trump", | |
presvote16post_2016 == 3 ~ "Johnson", | |
presvote16post_2016 == 4 ~ "Stein", | |
presvote16post_2016 == 5 ~ "McMullin", | |
presvote16post_2016 == 6 ~ "Other", | |
presvote16post_2016 == 7 ~ "No Vote")) %>% | |
select(vote, pct) %>% | |
mutate(prim = "Cruz") | |
## Mapping Primary Choice onto General Election Choice #### | |
eee1 <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pp_repprim16_2016 ==1) %>% | |
filter(presvote16post_2016 <= 3) %>% | |
ct(presvote16post_2016, wt = weight_2017) %>% | |
mutate(vote = frcode(presvote16post_2016 == 1 ~ "Clinton", | |
presvote16post_2016 == 2 ~ "Trump", | |
presvote16post_2016 == 3 ~ "Johnson", | |
presvote16post_2016 == 4 ~ "Stein", | |
presvote16post_2016 == 5 ~ "McMullin", | |
presvote16post_2016 == 6 ~ "Other", | |
presvote16post_2016 == 7 ~ "No Vote")) %>% | |
select(vote, pct) %>% | |
mutate(prim = "Trump") | |
eee2 <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pp_repprim16_2016 ==2) %>% | |
filter(presvote16post_2016 <= 3) %>% | |
ct(presvote16post_2016, wt = weight_2017) %>% | |
mutate(vote = frcode(presvote16post_2016 == 1 ~ "Clinton", | |
presvote16post_2016 == 2 ~ "Trump", | |
presvote16post_2016 == 3 ~ "Johnson", | |
presvote16post_2016 == 4 ~ "Stein", | |
presvote16post_2016 == 5 ~ "McMullin", | |
presvote16post_2016 == 6 ~ "Other", | |
presvote16post_2016 == 7 ~ "No Vote")) %>% | |
select(vote, pct) %>% | |
mutate(prim = "Kasich") | |
eee3 <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(pp_repprim16_2016 ==4) %>% | |
filter(presvote16post_2016 <= 3) %>% | |
ct(presvote16post_2016, wt = weight_2017) %>% | |
mutate(vote = frcode(presvote16post_2016 == 1 ~ "Clinton", | |
presvote16post_2016 == 2 ~ "Trump", | |
presvote16post_2016 == 3 ~ "Johnson", | |
presvote16post_2016 == 4 ~ "Stein", | |
presvote16post_2016 == 5 ~ "McMullin", | |
presvote16post_2016 == 6 ~ "Other", | |
presvote16post_2016 == 7 ~ "No Vote")) %>% | |
select(vote, pct) %>% | |
mutate(prim = "Rubio") | |
graph <- bind_df("eee") | |
graph %>% | |
na.omit() %>% | |
ggplot(., aes(x = vote, y = pct, fill = vote)) + | |
geom_col(color = "black", position = "dodge") + | |
scale_fill_manual(values = c("dodgerblue3", "firebrick3", "goldenrod")) + | |
facet_wrap(~ prim, ncol =2) + | |
scale_y_continuous(labels = percent) + | |
theme_gg("Abel") + | |
labs(x = "", y = "", title ="Republican Primary Voters Choice in the General Election", subtitle = "Among White Evangelicals", caption = "Voter Study Group 2016") + | |
geom_text(aes(y = pct + .055, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 10, family = "font") + | |
ggsave("D://cces/images/vp_primary_general.png", width = 6) | |
### This is the last graph - Primary Coalitions onto General #### | |
fff <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(presvote16post_2016 != "NA") %>% | |
filter(pp_repprim16_2016 != "NA") %>% | |
group_by(pp_repprim16_2016) %>% | |
ct(presvote16post_2016) %>% | |
filter(presvote16post_2016 ==2) %>% | |
select(-pct, -presvote16post_2016) %>% | |
mutate(pct = n/720) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ", | |
pp_repprim16_2016 == 6 ~ " Don`t Recall")) %>% | |
ungroup(pp_repprim16_2016) %>% | |
select(cand, pct) | |
fff2 <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(presvote16post_2016 != "NA") %>% | |
filter(pp_demprim16_2016 != "NA") %>% | |
group_by(pp_demprim16_2016) %>% | |
ct(presvote16post_2016) %>% | |
filter(presvote16post_2016 ==2) %>% | |
select(-pct, -presvote16post_2016) %>% | |
mutate(pct = n/720) %>% | |
mutate(cand = frcode(pp_demprim16_2016 == 1 ~ " Clinton ", | |
pp_demprim16_2016 == 2 ~ " Sanders ", | |
pp_demprim16_2016 == 3 ~ " Someone Else ", | |
pp_demprim16_2016 == 4 ~ " Don't Recall ")) %>% | |
ungroup(pp_demprim16_2016) %>% | |
select(cand, pct) | |
graph <- bind_df("fff") | |
trump <- graph %>% | |
arrange(-pct) %>% | |
head(5) %>% | |
add_row(cand = " All Others ", pct = .075) %>% | |
mutate(group = "Trump") | |
fff <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(presvote16post_2016 != "NA") %>% | |
filter(pp_repprim16_2016 != "NA") %>% | |
group_by(pp_repprim16_2016) %>% | |
ct(presvote16post_2016) %>% | |
filter(presvote16post_2016 ==1) %>% | |
select(-pct, -presvote16post_2016) %>% | |
mutate(pct = n/183) %>% | |
mutate(cand = frcode(pp_repprim16_2016 == 1 ~ " Trump ", | |
pp_repprim16_2016 == 3 ~ " Cruz ", | |
pp_repprim16_2016 == 4 ~ " Rubio ", | |
pp_repprim16_2016 == 2 ~ " Kasich ", | |
pp_repprim16_2016 == 5 ~ " Someone Else ", | |
pp_repprim16_2016 == 6 ~ " Don`t Recall")) %>% | |
ungroup(pp_repprim16_2016) %>% | |
select(cand, pct) | |
fff2 <- vp %>% | |
filter(evangelical_baseline ==1) %>% | |
filter(race_baseline ==1) %>% | |
filter(presvote16post_2016 != "NA") %>% | |
filter(pp_demprim16_2016 != "NA") %>% | |
group_by(pp_demprim16_2016) %>% | |
ct(presvote16post_2016) %>% | |
filter(presvote16post_2016 ==1) %>% | |
select(-pct, -presvote16post_2016) %>% | |
mutate(pct = n/183) %>% | |
mutate(cand = frcode(pp_demprim16_2016 == 1 ~ " Clinton ", | |
pp_demprim16_2016 == 2 ~ " Sanders ", | |
pp_demprim16_2016 == 3 ~ " Someone Else ", | |
pp_demprim16_2016 == 4 ~ " Don't Recall ")) %>% | |
ungroup(pp_demprim16_2016) %>% | |
select(cand, pct) | |
graph <- bind_df("fff") | |
clinton <- graph %>% | |
arrange(-pct) %>% | |
head(5) %>% | |
add_row(cand = " All Others ", pct = .055) %>% | |
mutate(group = "Clinton") | |
graph <- bind_rows(trump, clinton) | |
graph$cand <- factor(graph$cand, levels = c(" Trump ", " Cruz ", " Rubio ", " Kasich ", " Clinton ", " Sanders ", " All Others ")) | |
graph %>% | |
mutate(pct = round(pct, 3)) %>% | |
ggplot(., aes(x = 1, y = pct, fill = fct_rev(cand))) + | |
geom_col(color = "black") + | |
coord_flip() + | |
facet_wrap(~ group, ncol =1) + | |
scale_fill_manual(values = c(' Trump ' = "#990000", ' Cruz ' = "#ff3232", ' Rubio ' = "#ff6666", ' Kasich ' = "#ff9999", ' Sanders ' = "#6666ff", ' Clinton ' = "#1919ff", ' All Others ' = "azure3")) + | |
theme_gg("Abel") + | |
theme(legend.position = "bottom") + | |
scale_y_continuous(labels = percent) + | |
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) + | |
geom_text(aes(label = paste0(pct*100, '%')), position = position_stack(vjust = 0.5), size = 14, family = "font") + | |
labs(x = "", y = "", title = "Primary Vote Choice Translated to the General Election", subtitle = "Among White Evangelicals", caption = "Data: Voter Study Group") + | |
ggsave("D://cces/images/vp_horiz_bars.png", width = 12) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment