Skip to content

Instantly share code, notes, and snippets.

@ryanburge

ryanburge/atheist_active.R Secret

Created Apr 13, 2020
Embed
What would you like to do?
Atheist politically active
## Getting the data ready ####
reg <- cces18 %>%
mutate(act1 = car::recode(CC18_417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC18_417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC18_417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC18_417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC18_417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC18_417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
mutate(trad = frcode(evangelical == 1 & race == 1 ~ "White Evangelical",
evangelical == 1 & race != 1 ~ "Non-White Evangelical",
mainline == 1 ~ "Mainline",
bprot == 1 ~ "Black Prot.",
religpew == 2 & race == 1 ~ "White Catholic",
religpew == 2 & race != 1 ~ "Non-White Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 5 ~ "Jewish",
religpew == 6 ~ "Muslim",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
religpew == 12 ~ "Something Else",
TRUE ~ "Unclassified")) %>%
mutate(trad2 = frcode(religpew == 1 ~ "Protestant",
religpew == 2 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic")) %>%
mutate(male = car::recode(gender, "1=1; else =0")) %>%
mutate(white = car::recode(race, "1=1; else =0")) %>%
mutate(income = faminc_new) %>%
mutate(pid2 = frcode(pid3 == 1 ~ "Democrat",
pid3 == 2 ~ "Republican")) %>%
mutate(age = 2018- birthyr) %>%
select(acts, trad, trad2, male, white, age, income, pid2, educ, act1, act2, act3, act4, act5, act6)
### First Figure ####
bbb1 <- reg %>%
group_by(trad) %>%
mean_ci(act1) %>%
mutate(type = "Attend Political Meeting") %>%
na.omit()
bbb2 <- reg %>%
group_by(trad) %>%
mean_ci(act2) %>%
mutate(type = "Put up Political Sign") %>%
na.omit()
bbb3 <- reg %>%
group_by(trad) %>%
mean_ci(act3) %>%
mutate(type = "Work for Candidate") %>%
na.omit()
bbb4 <- reg %>%
group_by(trad) %>%
mean_ci(act4) %>%
mutate(type = "Attend a March/Protest") %>%
na.omit()
bbb5 <- reg %>%
group_by(trad) %>%
mean_ci(act5) %>%
mutate(type = "Contact Public Official") %>%
na.omit()
bbb6 <- reg %>%
group_by(trad) %>%
mean_ci(act6) %>%
mutate(type = "Donate Money to Candidate") %>%
na.omit()
graph <- bind_df("bbb")
graph %>%
filter(trad != "Unclassified") %>%
filter(trad != "Something Else") %>%
filter(n >= 500) %>%
ggplot(., aes(x = trad, y = mean, fill = trad)) +
geom_col(color = "black") +
facet_wrap(~ type, ncol = 2) +
y_pct() +
theme_gg("Abel") +
coord_flip() +
lab_bar(top = FALSE, type = mean, pos = .04, sz = 3) +
error_bar() +
scale_fill_tableau(palette = "Tableau 20") +
labs(x = "", y = "", title = "Political Activity in the Last 12 Months", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://polact_trads_all.png", type = "cairo-png", width = 7, height = 10)
## First Interaction ####
reg1 <- lm(acts ~ educ*trad2 + male + white + income + age, data = reg)
gg <- interact_plot(reg1, pred= educ, modx= trad2, modx.labels = c("Protestant", "Catholic", "Atheist", "Agnostic"), int.width = .76, interval = TRUE)
gg +
theme_gg("Abel", legend = FALSE) +
add_text(x = 4.1, y = 1.7, word = "Atheist", sz = 4) +
add_text(x = 5, y = 1.49, word = "Agnostic", sz = 4) +
add_text(x = 4.75, y = 1.25, word = "Prot.", sz = 4) +
add_text(x = 5.2, y = 1.1, word = "Catholic", sz = 4) +
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Less\nthan HS", "HS Grad", "Some\nCollege", "2 yr.", "4 yr.", "Post-\nGrad")) +
labs(x = "Education", y = "Predicted # of Political Activites (6 max)", title = "Atheists/Agnostics are Incredibly Politically Active", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://ath_polact.png", type = "cairo-png", width = 6)
## Second Interaction ####
reg1 <- lm(acts ~ educ*trad2*pid2 + male + white + income + age, data = reg)
gg <- interact_plot(reg1, pred= educ, modx= pid2, mod2 = trad2, mod2.labels = c("Protestant", "Catholic", "Atheist", "Agnostic"), int.width = .76, interval = TRUE)
gg +
theme_gg("Abel", legend = TRUE) +
scale_color_manual(values = c("dodgerblue3", "firebrick3")) +
scale_fill_manual(values = c("dodgerblue3", "firebrick3")) +
scale_x_continuous(breaks = c(1,2,3,4,5,6), labels = c("Less\nthan HS", "HS Grad", "Some\nCollege", "2 yr.", "4 yr.", "Post-\nGrad")) +
labs(x = "Education", y = "Predicted # of Political Activites (6 max)", title = "Atheists/Agnostics are Incredibly Politically Active", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://ath_polact_pid2.png", type = "cairo-png", width = 8)
## Time Series ####
reg08 <- cces08 %>%
mutate(act1 = car::recode(CC415_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC415_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC415_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC415_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC415_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC415_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew = V219) %>%
mutate(year = 2008)
reg10 <- cces10 %>%
mutate(act1 = car::recode(CC417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew = V219) %>%
mutate(year = 2010)
reg12 <- cces12 %>%
mutate(act1 = car::recode(CC417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew) %>%
mutate(year = 2012)
reg14 <- cces14 %>%
mutate(act1 = car::recode(CC417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew) %>%
mutate(year = 2014)
reg16 <- cces16 %>%
mutate(act1 = car::recode(CC16_417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC16_417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC16_417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC16_417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC16_417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC16_417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew) %>%
mutate(year = 2016)
reg18 <- cces18 %>%
mutate(act1 = car::recode(CC18_417a_1, "1=1; 2=0")) %>%
mutate(act2 = car::recode(CC18_417a_2, "1=1; 2=0")) %>%
mutate(act3 = car::recode(CC18_417a_3, "1=1; 2=0")) %>%
mutate(act4 = car::recode(CC18_417a_4, "1=1; 2=0")) %>%
mutate(act5 = car::recode(CC18_417a_5, "1=1; 2=0")) %>%
mutate(act6 = car::recode(CC18_417a_6, "1=1; 2=0")) %>%
mutate(acts = act1 + act2 + act3 + act4 + act5 + act6) %>%
select(starts_with("act"), religpew) %>%
mutate(year = 2018)
all <- bind_df("reg") %>% as_tibble()
all <- all %>%
mutate(trad = frcode(religpew == 1 ~ "Protestant",
religpew == 2 ~ "Catholic",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic"))
graph <- all %>%
group_by(year, trad) %>%
mean_ci(acts) %>%
na.omit()
graph %>%
filter(year >= 2010) %>%
ggplot(., aes(x = year, y = mean, color = trad, group = trad)) +
geom_point() +
geom_line() +
scale_color_d3() +
scale_fill_d3() +
geom_ribbon(aes(ymin = lower, ymax = upper, color = trad, group = trad), alpha = .2) +
theme_gg("Abel") +
add_text(x = 2017.3, y = 1.6, word = "Atheists", sz = 4) +
add_text(x = 2017, y = 1.33, word = "Agnostics", sz = 4) +
add_text(x = 2017.35, y = 1.1, word = "Prot.", sz = 4) +
add_text(x = 2016.5, y = 1.1, word = "Cath.", sz = 4) +
labs(x = "", y = "Number of Political Acts (Out of Six)", title = "Political Activity Has Shifted Rapidly Since 2016", caption = "@ryanburge\nData: CCES 2010-2018") +
ggsave("E://polacts_timeseries.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment