Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created September 9, 2019 20:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/eb9846a031041e8033918eb1ae886ccc to your computer and use it in GitHub Desktop.
Save ryanburge/eb9846a031041e8033918eb1ae886ccc to your computer and use it in GitHub Desktop.
Mainline Conservatives
pid_fun <- function(df, denom, num, name){
denom <- enquo(denom)
df %>%
mutate(pid3 = frcode(pid7 == 1 | pid7 == 2 | pid7 == 3 ~ "Democrat",
pid7 == 4 ~ "Independent",
pid7 == 5 | pid7 == 6 | pid7 == 7 ~ "Republican")) %>%
filter(!! denom == num) %>%
ct(pid3, wt = commonweight, show_na = FALSE) %>%
mutate(group = name)
}
aaa1 <- cces18 %>% pid_fun(religpew_methodist, 1, "United Methodist")
aaa2 <- cces18 %>% pid_fun(religpew_lutheran, 1, "Evangelical Lutheran Church of America")
aaa3 <- cces18 %>% pid_fun(religpew_presby, 1, "Presbyterian Church - USA")
aaa4 <- cces18 %>% pid_fun(religpew_protestant, 7, "Episcopal")
aaa5 <- cces18 %>% pid_fun(religpew_baptist, 2, "American Baptist Churches of the USA")
aaa6 <- cces18 %>% pid_fun(religpew_congreg, 1, "United Church of Christ")
aaa7 <- cces18 %>% pid_fun(religpew_christian, 1, "Disciples of Christ")
graph <- bind_df("aaa")
graph %>%
ggplot(., aes(x=1, y = pct, fill =fct_rev(pid3))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ group, ncol =1) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_fill_manual(values = c("firebrick3", "azure3", "dodgerblue3")) +
y_pct() +
guides(fill = guide_legend(reverse=T, nrow =1)) +
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 = 4, family = "font") +
theme(panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.y = element_blank()) +
theme(plot.title = element_text(size = 16)) +
labs(x = "", y = "", title = "Party Identification of Large Mainline Denominations", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://seven_sisters.png", type = "cairo-png", height = 6, width = 6)
bbb1 <- cces18 %>% pid_fun(religpew_baptist, 1, "Southern Baptist Convention")
bbb2 <- cces18 %>% pid_fun(religpew_lutheran, 2, "Lutheran - MO Synod")
bbb3 <- cces18 %>% pid_fun(religpew_nondenom, 1, "Nondenominational Evangelical")
bbb4 <- cces18 %>% pid_fun(religpew_pentecost, 1, "Assemblies of God")
bbb5 <- cces18 %>% pid_fun(religpew_christian, 1, "Church of Christ")
bbb6 <- cces18 %>% pid_fun(religpew, 3, "Mormons")
graph <- bind_df("bbb")
graph %>%
ggplot(., aes(x=1, y = pct, fill =fct_rev(pid3))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ group, ncol =1) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_fill_manual(values = c("firebrick3", "azure3", "dodgerblue3")) +
y_pct() +
guides(fill = guide_legend(reverse=T, nrow =1)) +
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 = 4, family = "font") +
theme(panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.y = element_blank()) +
theme(plot.title = element_text(size = 16)) +
labs(x = "", y = "", title = "Party Identification of Large Evangelical Denominations", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://seven_sisters_evan.png", type = "cairo-png", height = 6, width = 6)
gg <- gss %>%
filter(partyid <=6) %>%
mutate(trad = frcode(evangelical == 1 ~ "Evangelical",
mainline == 1 ~ "Mainline")) %>%
group_by(year, trad) %>%
mean_ci(partyid, wt = wtssall)
gg <- gg %>% na.omit()
gg1 <- gss %>%
filter(partyid <=6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(trad = "Entire Sample")
ggg <- bind_rows(gg, gg1)
ggg %>%
ggplot(., aes(x = year, y = mean, color = trad, group = trad)) +
geom_point(size=3, color="white") +
geom_point(size=2, shape=1, alpha=.5) +
geom_point(size=1, shape=19) +
scale_color_tableau() +
theme_gg("Abel") +
add_text(x = 2012, y = 3.25, word = "Mainline", sz = 4) +
add_text(x = 2012, y = 3.52, word = "Evangelical", sz = 4) +
add_text(x = 2012, y = 2.835, word = "Entire Sample", sz = 4) +
geom_smooth(linetype = "twodash", se = FALSE) +
scale_x_continuous(breaks = c(1970, 1980, 1990, 2000, 2010)) +
scale_y_continuous(limits = c(2,4), breaks = c(2,3,4), labels = c("Ind., Near Dem.", "Independent", "Ind., Near Rep.")) +
labs(x = "", y = "", title = "Mean Partisanship of Religious Traditions", caption = "@ryanburge\nData: GSS 1972-2018") +
ggsave("E://pid_3trads.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment