Skip to content

Instantly share code, notes, and snippets.

@ryanburge

ryanburge/mormon_2020.R Secret

Last active Oct 25, 2020
Embed
What would you like to do?
Mormons in 2020
gg <- cces16 %>%
filter(religpew == 3) %>%
mutate(vote = CC16_410a) %>%
mutate(vote = frcode(vote == 1 ~ "Trump",
vote == 2 ~ "Clinton",
vote == 3 ~ "Johnson",
vote == 4 ~ "Stein",
vote == 8 ~ "McMullin")) %>%
ct(vote, wt = commonweight_vv_post, show_na = FALSE)
gg %>%
ggplot(., aes(x = vote, y = pct, fill = vote)) +
geom_col(color = "black") +
scale_fill_manual(values = c("firebrick3", "dodgerblue3", "goldenrod", "forestgreen", "darkorchid")) +
theme_gg("Abel") +
y_pct() +
labs(x = "", y = "", title = "LDS Voting in 2016", caption = "@ryanburge\nData: CCES 2016") +
lab_bar(top = TRUE, type = pct, pos = .02, sz = 4) +
ggsave("E://mormon_vote2016.png", type = "cairo-png", width = 4)
gg1 <- cces18 %>%
filter(religpew == 3) %>%
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.")) %>%
ct(pid, wt = commonpostweight, show_na = FALSE) %>%
mutate(survey = "CCES 2018")
gg2 <- ns %>%
filter(religion == 3) %>%
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.")) %>%
ct(pid, wt = weight, show_na = FALSE) %>%
mutate(survey = "NS 2019-20")
pid <- bind_rows(gg1, gg2)
top <- pid %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(pid))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ survey, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("#8D021F", "#B2182B","#EF8A62","azure4", "#67A9CF", "#2166AC", "#000080", "darkorchid")) +
theme_gg("Abel") +
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 = "Among Mormons", caption = "") +
ggsave("E://mormon_compare.png", width = 9, height = 3)
gg1 <- cces18 %>%
filter(religpew == 3) %>%
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) %>%
na.omit() %>%
mutate(survey = "CCES 2018")
gg2 <- ns %>%
filter(religion == 3) %>%
filter(ideo5 <= 5) %>%
mutate(ideo = frcode(ideo5 == 1 ~ "Very Liberal",
ideo5 == 2 ~ "Liberal",
ideo5 == 3 ~ "Moderate",
ideo5 == 4 ~ "Conservative",
ideo5 == 5 ~ "Very Conservative")) %>%
ct(ideo, wt = weight, show_na = FALSE) %>%
mutate(survey = "NS 2019-2020")
ideo <- bind_rows(gg1, gg2)
bottom <- ideo %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(ideo))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ survey, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("#B2182B","#EF8A62","azure4", "#67A9CF", "#2166AC")) +
theme_gg("Abel") +
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 = "Ideological Distribution", subtitle = "", caption = "@ryanburge\nData: CCES 2018 + Nationscape 2019-2020") +
ggsave("E://mormon_ideo_compare.png", width = 9, height = 3)
library(patchwork)
both <- top / bottom
ggsave("E://mormon_compare_both.png", type = "cairo-png", both, height = 6)
ns$month <- stringr::str_extract(ns$wave, "^.{2}")
ns <- ns %>%
mutate(month = as.numeric(month)) %>%
mutate(month = frcode(month == 7 ~ "July 2019",
month == 8 ~ "August 2019",
month == 9 ~ "September 2019",
month == 10 ~ "October 2019",
month == 11 ~ "November 2019",
month == 12 ~ "December 2019",
month == 1 ~ "January 2020",
month == 2 ~ "February 2020",
month == 3 ~ "March 2020",
month == 4 ~ "April 2020",
month == 5 ~ "May 2020",
month == 6 ~ "June 2020"))
gg <- ns %>%
mutate(app = frcode(pres_approval == 4 ~ "Strongly Disappove",
pres_approval == 3 ~ "Somewhat Disapprove",
pres_approval == 2 ~ "Somewhat Approve",
pres_approval == 1 ~ "Strongly Approve")) %>%
filter(religion == 3) %>%
group_by(month) %>%
ct(app, wt = weight, show_na = FALSE)
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(app))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ month, ncol =1, strip.position = "left") +
fill5_scale() +
theme_gg("Abel") +
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 = "black") +
labs(x = "", y = "", title = "Do you approve or disapprove of the way Donald Trump is handling his job as president?", subtitle = "Among Mormons", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://mormon_approval.png", width = 9, height = 6)
ns <- read.fst("D://ns_full.fst")
fun <- function(df, var, name){
df %>%
filter(religion == 3) %>%
mutate(never = case_when({{var}} == 1 ~ 1,
{{var}} == 2 ~ 0)) %>%
mutate(app = frcode(pres_approval == 4 ~ "Strongly\nDisapprove",
pres_approval == 3 ~ "Somewhat\nDisapprove",
pres_approval == 2 ~ "Somewhat\nApprove",
pres_approval == 1 ~ "Strongly\nApprove")) %>%
mean_ci(never, wt = weight) %>%
na.omit() %>%
mutate(issue = name)
}
ppp1 <- ns %>% fun(guns_bg, "Background Checks") %>% mutate(type = "In Opposition to Trump")
ppp2 <- ns %>% fun(raise_upper_tax, "Raise Taxes on Wealthy") %>% mutate(type = "In Opposition to Trump")
ppp3 <- ns %>% fun(college, "Debt Free College") %>% mutate(type = "Divided")
ppp4 <- ns %>% fun(abortion_never, "Never Permit Abortion") %>% mutate(type = "In Opposition to Trump")
ppp5 <- ns %>% fun(china_tariffs, "Impose Tariffs on China") %>% mutate(type = "Divided")
ppp6 <- ns %>% fun(china_tariffs, "Charge Border\nCrossers w/Felony") %>% mutate(type = "Divided")
ppp7 <- ns %>% fun(environment, "Big Investment in\nTech for Environment") %>% mutate(type = "In Opposition to Trump")
ppp8 <- ns %>% fun(guaranteed_jobs, "Federal Jobs Guarantee") %>% mutate(type = "Divided")
ppp9 <- ns %>% fun(estate_tax, "Eliminate Estate Tax") %>% mutate(type = "In Line With Trump")
ppp10 <- ns %>% fun(wall, "Build a Wall on Southern Border") %>% mutate(type = "Divided")
ppp11 <- ns %>% fun(cap_carbon, "Cap Carbon Emissions") %>% mutate(type = "In Opposition to Trump")
ppp12 <- ns %>% fun(abolish_priv_insurance, "Abolish Private Insurance") %>% mutate(type = "In Line With Trump")
ppp13 <- ns %>% fun(green_new_deal, "Green New Deal") %>% mutate(type = "Divided")
ppp14 <- ns %>% fun(gun_registry, "Federal Gun Registry") %>% mutate(type = "Divided")
ppp15 <- ns %>% fun(immigration_separation, "Family Separation Policy") %>% mutate(type = "In Opposition to Trump")
ppp16 <- ns %>% fun(israel, "Withdraw Military\nIn Line With Trump for Israel") %>% mutate(type = "In Line With Trump")
ppp17 <- ns %>% fun(marijuana, "Legalize Marijuana") %>% mutate(type = "Divided")
ppp18 <- ns %>% fun(maternityleave, "Paid Maternity Leave") %>% mutate(type = "In Opposition to Trump")
ppp19 <- ns %>% fun(military_size, "Reduce Size of the Military") %>% mutate(type = "In Line With Trump")
ppp20 <- ns %>% fun(minwage, "Raise Min. Wage to $15/hr.") %>% mutate(type = "Divided")
ppp21 <- ns %>% fun(muslimban, "Muslim Travel Ban") %>% mutate(type = "In Opposition to Trump")
ppp22 <- ns %>% fun(reparations, "Reparations") %>% mutate(type = "In Line With Trump")
ppp23 <- ns %>% fun(saudi_arabia, "Withdraw Military\nIn Line With Trump for Saudi Arabia") %>% mutate(type = "Divided")
ppp24 <- ns %>% fun(ten_commandments, "10 Commandments in Schools") %>% mutate(type = "In Line With Trump")
ppp25 <- ns %>% fun(trans_military, "Allow Trans in the Military") %>% mutate(type = "Divided")
ppp26 <- ns %>% fun(dreamers, "DREAM Act") %>% mutate(type = "In Opposition to Trump")
ppp27 <- ns %>% fun(deportation, "Deport All Illegal Immigrants") %>% mutate(type = "Divided")
ppp28 <- ns %>% fun(vouchers, "School Vouchers") %>% mutate(type = "Divided")
ppp29 <- ns %>% fun(limit_magazines, "Limit Magazine Size") %>% mutate(type = "Divided")
ppp30 <- ns %>% fun(right_to_work, "Right to Work") %>% mutate(type = "Divided")
graph <- bind_df("ppp")
graph %>%
ggplot(., aes(x = reorder(issue, mean), y= mean, fill = type)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_manual(values = c("azure3", "firebrick3", "dodgerblue3")) +
theme_gg("Abel", legend = TRUE) +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = mean, pos = .03, sz = 5) +
theme(legend.text = element_text(size = 16)) +
labs(x = "", y = "Agree with the Policy", title = "LDS Policy Positions Compared to Trump's Position", caption = "@ryanburge\nData: Nationscape (2019-2020)") +
ggsave("E://ns_appr_white_mormon.png", type = "cairo-png", width = 12, height = 12)
gg <- ns %>%
filter(religion == 3) %>%
group_by(month) %>%
mutate(vote = frcode(trump_biden == 1 ~ "Biden",
trump_biden == 2 ~ "Trump")) %>%
ct(vote, wt = weight, show_na = FALSE)
gg %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ month, ncol =1, strip.position = "left") +
scale_fill_manual(values = c("firebrick3", "dodgerblue3")) +
theme_gg("Abel") +
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 = "black") +
labs(x = "", y = "", title = "2020 Presidential Matchup", subtitle = "Among Mormons", caption = "@ryanburge\nData: Nationscape 2019-2020") +
ggsave("E://mormon_h2h.png", width = 9, height = 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.