Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created July 8, 2024 15:41
Show Gist options
  • Save ryanburge/129fa8c3997de32bf66666b2343ecec5 to your computer and use it in GitHub Desktop.
Save ryanburge/129fa8c3997de32bf66666b2343ecec5 to your computer and use it in GitHub Desktop.
gg1 <- gss %>%
filter(year <= 2020) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year) %>%
ct(gd, wt = wtssall, show_na = FALSE)
gg2 <- gss %>%
filter(year > 2020) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year) %>%
ct(gd, wt = wtssnrps, show_na = FALSE)
graph <- bind_rows(gg1, gg2)
graph %>%
ggplot(., aes(x = year, y = pct, color = gd, group = gd)) +
geom_point(stroke = .5, shape = 21, show.legend = FALSE) +
geom_smooth(se = FALSE) +
scale_color_gdocs() +
theme_rb(legend = TRUE) +
scale_y_continuous(labels = percent) +
theme(legend.text = element_text(size = 20)) +
labs(x = "Year", y = "", title = "Which statement comes closest to expressing what you believe about God?", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("god_belief_2022.png", ht = 10)
graph %>%
mutate(lab = round(pct, 3)) %>%
filter(year == 1988 | year == 2022) %>%
ggplot(., aes(x = factor(year), y = pct, fill = factor(year))) +
geom_col(color = "black") +
facet_wrap( ~ gd) +
theme_rb() +
scale_fill_calc() +
scale_y_continuous(labels = percent) +
theme(strip.text = element_text(size = 16)) +
theme(axis.text.x = element_text(size = 20)) +
geom_text(aes(y = pct + .035, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") +
labs(x = "Year", y = "", title = "Which statement comes closest to expressing\nwhat you believe about God?", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("god_belief_compare8822.png", wd = 6, ht = 9)
one <- gss %>%
filter(year >= 2006) %>%
filter(year <= 2020) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(god = case_when(god == 1 ~ 1,
god <= 6 ~ 0)) %>%
group_by(year, educ) %>%
mean_ci(god, wt = wtssall, ci = .84) %>%
filter(educ != "NA")
two <- gss %>%
filter(year >= 2020) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(god = case_when(god == 1 ~ 1,
god <= 6 ~ 0)) %>%
group_by(year, educ) %>%
mean_ci(god, wt = wtssnrps, ci = .84) %>%
filter(educ != "NA")
graph <- bind_rows(one, two) %>% filter(mean != "NA")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = educ, y = mean, fill = educ)) +
geom_col(color = "black") +
facet_wrap(~ year) +
error_bar() +
theme_rb() +
scale_y_continuous(labels = percent) +
lab_bar(top = FALSE, type = lab, pos = .01, sz = 6.5) +
theme(strip.text = element_text(size = 20)) +
scale_fill_manual(values = c("#E0826C", "#4DB6AC", "#AC73C2", "#99A78E")) +
labs(x = "Highest Level of Education", y = "", title = "Share Who Say 'I Do Not Believe in God'", caption = "@ryanburge\nData: General Social Survey, 2006-2022")
save("atheist_belief_educ.png", wd =7, ht = 10)
one <- gss %>%
filter(year >= 2006) %>%
filter(year <= 2020) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(god = case_when(god == 1 | god == 2 ~ 1,
god <= 6 ~ 0)) %>%
group_by(year, educ) %>%
mean_ci(god, wt = wtssall, ci = .84) %>%
filter(educ != "NA")
two <- gss %>%
filter(year >= 2020) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(god = case_when(god == 1 | god == 2 ~ 1,
god <= 6 ~ 0)) %>%
group_by(year, educ) %>%
mean_ci(god, wt = wtssnrps, ci = .84) %>%
filter(educ != "NA")
graph <- bind_rows(one, two) %>% filter(mean != "NA")
graph %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = educ, y = mean, fill = educ)) +
geom_col(color = "black") +
facet_wrap(~ year) +
error_bar() +
theme_rb() +
scale_y_continuous(labels = percent) +
lab_bar(top = FALSE, type = lab, pos = .02, sz = 6.5) +
theme(strip.text = element_text(size = 20)) +
scale_fill_manual(values = c("#E0826C", "#4DB6AC", "#AC73C2", "#99A78E")) +
labs(x = "Highest Level of Education", y = "", title = "Share Who Say 'I Do Not Believe in God' or 'I do not know whether there\nis a God and I do not believe there is any way to find out'", caption = "@ryanburge\nData: General Social Survey, 2006-2022")
save("atheist_agnostic_belief_educ.png", wd =7, ht = 10)
gg1 <- gss %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
filter(year <= 2020) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year, gender) %>%
ct(gd, wt = wtssall, show_na = FALSE)
gg2 <- gss %>%
mutate(gender = frcode(sex == 1 ~ "Men",
sex == 2 ~ "Women")) %>%
filter(year > 2020) %>%
mutate(gd = frcode(god == 1 ~ "Don't Believe",
god == 2 ~ "No Way to Find Out",
god == 3 ~ "Some Higher Power",
god == 4 ~ "Believe Sometimes",
god == 5 ~ "Believe But Doubts",
god == 6 ~ "Believe No Doubts")) %>%
group_by(year, sex) %>%
ct(gd, wt = wtssnrps, show_na = FALSE)
graph <- bind_rows(gg1, gg2) %>% filter(gender != "NA")
graph %>%
ggplot(., aes(x = year, y = pct, color = gender, group = gender)) +
geom_point(stroke = .5, shape = 21, show.legend = FALSE) +
geom_smooth(se = FALSE) +
scale_color_tableau() +
theme_rb(legend = TRUE) +
scale_y_continuous(labels = percent) +
theme(legend.text = element_text(size = 20)) +
facet_wrap(~ gd) +
theme(strip.text = element_text(size = 20)) +
labs(x = "Year", y = "", title = "Which statement comes closest to expressing what you believe about God?", caption = "@ryanburge\nData: General Social Survey, 1988-2022")
save("god_belief_2022_gender.png", ht = 10)
one <- gss %>%
filter(year >= 2006) %>%
filter(year <= 2020) %>%
select(educ, god, weight = wtssall) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(both = case_when(god == 1 | god == 2 ~ 1,
god <= 6 ~ 0)) %>%
mutate(ath = case_when(god == 1 ~ 1,
god <= 6 ~ 0)) %>%
mutate(certain = case_when(god == 6 ~ 1,
god <= 5 ~ 0))
two <- gss %>%
filter(year >= 2020) %>%
select(educ, god, weight = wtssnrps) %>%
mutate(educ = frcode(educ <= 12 ~ "HS\nor Less",
educ == 13 | educ == 14 | educ == 15 ~ "Some\nCollege",
educ == 16 ~ "College\nDegree",
educ >= 17 ~ "Grad.\nSchool")) %>%
mutate(both = case_when(god == 1 | god == 2 ~ 1,
god <= 6 ~ 0)) %>%
mutate(ath = case_when(god == 1 ~ 1,
god <= 6 ~ 0)) %>%
mutate(certain = case_when(god == 6 ~ 1,
god <= 5 ~ 0))
gg <- bind_rows(one, two)
aaa1 <- gg %>%
group_by(educ) %>%
mean_ci(both, wt = weight, ci = .84) %>%
filter(educ != "NA") %>%
mutate(grp = "Atheist or Agnostic Belief")
aaa2 <- gg %>%
group_by(educ) %>%
mean_ci(ath, wt = weight, ci = .84) %>%
filter(educ != "NA") %>%
mutate(grp = "Atheist Belief")
aaa3 <- gg %>%
group_by(educ) %>%
mean_ci(certain, wt = weight, ci = .84) %>%
filter(educ != "NA") %>%
mutate(grp = "Certain Belief")
both <- bind_rows(aaa1, aaa2, aaa3)
both %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = educ, y = mean, fill = educ)) +
geom_col(color = "black") +
facet_wrap(~ grp, ncol = 1) +
# error_bar() +
theme_rb() +
scale_y_continuous(labels = percent) +
geom_text(aes(y = .06, label = ifelse(grp == "Certain Belief", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font") +
geom_text(aes(y = mean + .05, label = ifelse(grp == "Atheist Belief", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font") +
geom_text(aes(y = mean + .05, label = ifelse(grp == "Atheist or Agnostic Belief", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 12, family = "font") +
theme(strip.text = element_text(size = 20)) +
scale_fill_manual(values = c("#E0826C", "#4DB6AC", "#AC73C2", "#99A78E")) +
labs(x = "Highest Level of Education", y = "", title = "Relationship Between Education and Belief in God", caption = "@ryanburge\nData: General Social Survey, 2006-2022")
save("atheist_agnostic_belief_educ_all.png", ht = 12, wd = 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment