Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conservative Christians vs Nones
gg <- cces %>%
mutate(grp = frcode(religion == 9 ~ "Atheist",
religion == 10 ~ "Agnostic",
religion == 11 ~ "Nothing in Particular")) %>%
mutate(con = case_when(ideo5 == 4 | ideo5 == 5 ~ 1,
ideo5 <= 3 ~ 0)) %>%
group_by(year, grp) %>%
mean_ci(con, wt = weight, ci = .84)
gg1 <- cces %>%
filter(religion <= 4) %>%
mutate(con = case_when(ideo5 == 4 | ideo5 == 5 ~ 1,
ideo5 <= 3 ~ 0)) %>%
group_by(year) %>%
mean_ci(con, wt = weight, ci = .84) %>%
mutate(grp = "Christians")
graph <- bind_rows(gg, gg1)
graph %>%
filter(year >= 2008) %>%
filter(grp != 'NA') %>%
ggplot(., aes(x = year, y = mean, color = grp)) +
geom_point(size=3, color="white") +
geom_point(size=2, shape=1) +
geom_point(size=1, shape=19) +
geom_line() +
y_pct() +
scale_color_gdocs() +
theme_rb() +
scale_x_continuous(breaks = c(2008, 2012, 2016, 2020)) +
add_text(x = 2014, y = .285, word = "Nothing in Particular", sz = 5) +
add_text(x = 2014, y = .17, word = "Agnostic", sz = 5) +
add_text(x = 2015, y = .09, word = "Atheist", sz = 5) +
add_text(x = 2015, y = .50, word = "Christian", sz = 5) +
labs(x = "", y = "", title = "Share Who Identify as Conservative", caption = "@ryanburge\nData: CES 2008-2020") +
ggsave("E://type_nones_cons.png", type = "cairo-png", width = 7)
cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
ct(grp, wt = commonweight)
# 17% of conservatives are nones, 74% are Christians ##
ggg1 <- cces08 %>%
filter(V243 == 4 | V243 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(vote = CC410) %>%
mutate(vote = frcode(vote == 1 ~ "Republican",
vote == 2 ~ "Democrat",
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>%
group_by(grp) %>%
ct(vote, wt = V201, show_na = FALSE) %>%
mutate(year = 2008)
ggg2 <- cces12 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(vote = CC410a) %>%
mutate(vote = frcode(vote == 1 ~ "Democrat",
vote == 2 ~ "Republican",
vote == 4 ~ "Third Party")) %>%
group_by(grp) %>%
ct(vote, wt = weight_vv_post, show_na = FALSE) %>%
mutate(year = 2012)
ggg3 <- cces16 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(vote = CC16_410a) %>%
mutate(vote = frcode(vote == 1 ~ "Republican",
vote == 2 ~ "Democrat",
vote == 3 | vote == 4 | vote == 5 | vote == 8 ~ "Third Party")) %>%
group_by(grp) %>%
ct(vote, wt = commonweight_vv_post, show_na = FALSE) %>%
mutate(year = 2016)
ggg4 <- cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(vote = CC20_410) %>%
mutate(vote = frcode(vote == 1 ~ "Democrat",
vote == 2 ~ "Republican",
vote == 4 ~ "Third Party")) %>%
group_by(grp) %>%
ct(vote, wt = commonpostweight, show_na = FALSE) %>%
mutate(year = 2020)
graph <- bind_rows(ggg1, ggg2, ggg3, ggg4) %>% na.omit()
graph %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(vote))) +
geom_col(color = "black") +
coord_flip() +
facet_grid(year ~ grp, switch = "y") +
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 >.055, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
labs(x = "", y = "", title = "Vote Choice for President", subtitle = "Among Conservatives", caption = "@ryanburge\nData: CCES 2008-2020") +
ggsave("E://vote_choice_cons.png", width = 9, height = 3.5)
fun <- function(df, var, name){
df %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(qq = {{var}}) %>%
mutate(qq = case_when(qq == 1 ~ 1,
qq == 2 ~ 0)) %>%
group_by(grp) %>%
mean_ci(qq, wt = commonweight, ci = .84) %>%
mutate(type = name) %>%
na.omit()
}
yyy1 <- cces20 %>% fun(CC20_355a, "Withdraw From Paris Climate Accord")
yyy2 <- cces20 %>% fun(CC20_333a, "Give EPA Power to Regulate CO2")
yyy3 <- cces20 %>% fun(CC20_355d, "Ban Transgender from Military")
yyy4 <- cces20 %>% fun(CC20_332a, "Always Allow Abortion")
yyy5 <- cces20 %>% fun(CC20_332e, "Prohibit Federal Funds for Abortion")
yyy6 <- cces20 %>% fun(CC20_355e, "Require Work for Food Stamps")
yyy7 <- cces20 %>% fun(CC20_330b, "Ban Assault Weapons")
yyy8 <- cces20 %>% fun(CC20_330c, "Make it Easier to Obtain Concealed Carry")
yyy9 <- cces20 %>% fun(CC20_331a, "Pathway to Citizenship")
yyy10 <- cces20 %>% fun(CC20_331d, "Reduce Legal Immigration by 50%")
yyy11 <- cces20 %>% fun(CC20_334a, "Eliminate Mandatory Minimums")
yyy12 <- cces20 %>% fun(CC20_334g, "End DoD Surplus to Local Police")
graph <- bind_df("yyy")
gg1 <- graph %>% filter(grp == "Nones") %>% select(grp, nones = mean, type)
gg2 <- graph %>% filter(grp == "Christians") %>% select(xtn = mean)
sort <- bind_cols(gg1, gg2) %>% mutate(diff = nones - xtn) %>% select(type, diff)
graph <- left_join(graph, sort)
graph$diff <- abs(graph$diff)
graph %>%
ggplot(., aes(x = reorder(type, -diff), y = mean, fill = grp)) +
geom_col(color = "black", position = "dodge") +
coord_flip() +
scale_fill_tableau() +
theme_rb(legend = TRUE) +
y_pct() +
error_bar() +
lab_bar(top = FALSE, type = mean, pos = .065, sz = 4) +
labs(x = "", y = "Share in Favor", title = "Issue Positions of Conservatives", caption = "@ryanburge\nData: CES 2020") +
ggsave("E://nones_xtn_conservative.png", type = "cairo-png", width = 7, height = 7)
ttt1 <- cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(q1 = CC20_441a) %>%
mutate(q1 = frcode(q1 == 5 ~ "Strongly Disagree",
q1 == 4 ~ "Somewhat Disagree",
q1 == 3 ~ "Neither",
q1 == 2 ~ "Somewhat Agree",
q1 == 1 ~ "Strongly Agree")) %>%
group_by(grp) %>%
ct(q1, show_na = FALSE, wt = commonweight) %>%
mutate(term = "The Irish, Italians, Jews and many other minorities overcame prejudice\nand worked their way up. Black should do the same without any special favors") %>%
mutate(year = 2020) %>%
na.omit()
ttt2 <- cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(q1 = CC20_441b) %>%
mutate(q1 = frcode(q1 == 5 ~ "Strongly Disagree",
q1 == 4 ~ "Somewhat Disagree",
q1 == 3 ~ "Neither",
q1 == 2 ~ "Somewhat Agree",
q1 == 1 ~ "Strongly Agree")) %>%
group_by(grp) %>%
ct(q1, show_na = FALSE, wt = commonweight) %>%
mutate(term = "Generations of slavery and discrimination have created conditions\nthat make it difficult for Blacks to work their way out of the lower class.") %>%
mutate(year = 2020) %>%
na.omit()
graph <- bind_rows(ttt1, ttt2)
top <- graph %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(q1))) +
geom_col(color = "black") +
coord_flip() +
facet_grid(grp ~ term, switch = "y") +
scale_fill_manual(values = c("#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51")) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
geom_text(aes(label = ifelse(q1 == "Strongly Agree" & pct > .06, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") +
labs(x = "", y = "", title = "Views of Racial Issues Among Conservatives", subtitle = "", caption = "") +
ggsave("E://resent_cons_nones_xtn1.png", width = 12, height = 4)
ttt3 <- cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(q1 = CC20_440a) %>%
mutate(q1 = frcode(q1 == 5 ~ "Strongly Disagree",
q1 == 4 ~ "Somewhat Disagree",
q1 == 3 ~ "Neither",
q1 == 2 ~ "Somewhat Agree",
q1 == 1 ~ "Strongly Agree")) %>%
group_by(grp) %>%
ct(q1, show_na = FALSE, wt = commonweight) %>%
mutate(term = "White people in the U.S. have certain advantages because of their skin color") %>%
mutate(year = 2020) %>%
na.omit()
ttt4 <- cces20 %>%
filter(ideo5 == 4 | ideo5 == 5) %>%
mutate(grp = frcode(religpew == 9 | religpew == 10 | religpew == 11 ~ "Nones",
religpew <= 4 ~ "Christians")) %>%
mutate(q1 = CC20_440b) %>%
mutate(q1 = frcode(q1 == 5 ~ "Strongly Disagree",
q1 == 4 ~ "Somewhat Disagree",
q1 == 3 ~ "Neither",
q1 == 2 ~ "Somewhat Agree",
q1 == 1 ~ "Strongly Agree")) %>%
group_by(grp) %>%
ct(q1, show_na = FALSE, wt = commonweight) %>%
mutate(term = "Racial problems in the U.S. are rare, isolated situations") %>%
mutate(year = 2020) %>%
na.omit()
graph <- bind_rows(ttt3, ttt4)
bot <- graph %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(q1))) +
geom_col(color = "black") +
coord_flip() +
facet_grid(grp ~ term, switch = "y") +
scale_fill_manual(values = c("#264653", "#2a9d8f", "#e9c46a", "#f4a261", "#e76f51")) +
theme_rb(legend = TRUE) +
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(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
geom_text(aes(label = ifelse(q1 == "Strongly Agree" & pct > .06, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") +
labs(x = "", y = "", title = "", subtitle = "", caption = "@ryanburge\nData: CES 2020") +
ggsave("E://resent_cons_nones_xtn2.png", width = 12, height = 4)
library(patchwork)
both <- top / bot
ggsave("E://patch_nones_xtn.png", type = "cairo-png", both, width = 11, height = 6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment