Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Last active May 7, 2019 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/4a84b7d22487debcfdddd52c034ac114 to your computer and use it in GitHub Desktop.
Save ryanburge/4a84b7d22487debcfdddd52c034ac114 to your computer and use it in GitHub Desktop.
View of the Bible PID.
g1 <- gss %>%
filter(year == 1988 | year == 1998 | year == 2008 | year == 2018) %>%
filter(partyid == 0 | partyid == 1 | partyid == 2) %>%
filter(bible != "NA") %>%
filter(bible != 4) %>%
group_by(year) %>%
ct(bible, wt = wtssall) %>%
mutate(bible = frcode(bible == 1 ~ " Literal Word of God ",
bible == 2 ~ " Inspired Word of God ",
bible == 3 ~ " Ancient Book of Fables "))
g1 %>%
ggplot(., aes(x=1, y = pct, fill = fct_rev(bible))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_fill_paletteer_d(dutchmasters, pearl_earring) +
scale_y_continuous(labels = percent) +
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", color = "black") +
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 = "How has the View of the Bible Changed Among Democrats?", caption = "@ryanburge\nData: GSS 1978-2018") +
ggsave("E://dem_gss_time_bible.png", type = "cairo-png")
g1 <- gss %>%
filter(year == 1988 | year == 1998 | year == 2008 | year == 2018) %>%
filter(partyid == 4 | partyid == 5 | partyid == 6) %>%
filter(bible != "NA") %>%
filter(bible != 4) %>%
group_by(year) %>%
ct(bible, wt = wtssall) %>%
mutate(bible = frcode(bible == 1 ~ " Literal Word of God ",
bible == 2 ~ " Inspired Word of God ",
bible == 3 ~ " Ancient Book of Fables "))
g1 %>%
ggplot(., aes(x=1, y = pct, fill = fct_rev(bible))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_fill_paletteer_d(dutchmasters, pearl_earring) +
scale_y_continuous(labels = percent) +
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", color = "black") +
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 = "How has the View of the Bible Changed Among Republicans?", caption = "@ryanburge\nData: GSS 1978-2018") +
ggsave("E://gop_gss_time_bible.png", type = "cairo-png")
g1 <- gss %>%
filter(bible != "NA") %>%
filter(bible != 4) %>%
group_by(year) %>%
ct(bible, wt = wtssall) %>%
mutate(bible = frcode(bible == 3 ~ " Ancient Book of Fables ",
bible == 2 ~ " Inspired Word of God ",
bible == 1 ~ " Literal Word of God "))
g1 %>%
ggplot(., aes(x = year, y = pct, group = bible, color = bible)) +
geom_point() +
geom_line() +
theme_gg("Abel") +
guides(fill = guide_legend(reverse=T, nrow =1)) +
scale_color_paletteer_d(dutchmasters, pearl_earring) +
scale_y_continuous(labels = percent) +
annotate("text", x=2002, y =.18, label = "Ancient Book\nof Fables", size = 3, family = "font") +
annotate("text", x=2002, y =.36, label = "Literal Word\nof God", size = 3, family = "font") +
annotate("text", x=2006, y =.52, label = "Inspired Word\nof God", size = 3, family = "font") +
labs(x = "", y = "", title = "The View of the Bible Over Time", caption = "@ryanburge\nData: GSS 1984-2018") +
ggsave("E://bible_view_time.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment