Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created November 23, 2023 02:22
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/1a8dadc7e6579211f739d9efb3ca0a2b to your computer and use it in GitHub Desktop.
Save ryanburge/1a8dadc7e6579211f739d9efb3ca0a2b to your computer and use it in GitHub Desktop.
fire <- read_csv("E://data/fire24.csv")
ff <- fire %>%
filter(age == 18) %>%
mutate(rel = frcode(religion == 1 | religion == 12 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 3 ~ "Mormon",
religion == 4 ~ "Orthodox",
religion == 5 ~ "Jewish",
religion == 6 ~ "Muslim",
religion == 7 ~ "Buddhist",
religion == 8 ~ "Hindu",
religion == 9 ~ "Atheist",
religion == 10 ~ "Agnostic",
religion == 11 ~ "Nothing in Particular",
religion == 13 ~ "Other")) %>%
ct(rel, wt = weight, show_na = FALSE) %>%
mutate(type = "Entire\nSample")
library(googlesheets4)
harvard <- read_sheet("https://docs.google.com/spreadsheets/d/1Ljy9hPaQj1Z5I9UYcOKnx8EdLRAxFyh1YbjqCq3JeIM/edit?usp=sharing")
both <- bind_rows(ff, harvard)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = reorder(type, pct), y = pct, fill = type)) +
geom_col(color = "black") +
facet_wrap(~ rel) +
scale_y_continuous(labels = percent, limits = c(0, .35)) +
geom_text(aes(y = pct + .02, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 7, family = "font") +
theme_rb() +
scale_fill_calc() +
labs(x = "", y = "", title = "Comparing Havard's Freshmen Class With\nOther Freshmen Classes", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024 + Harvard Crimson's Meet the Class of 2027")
save("harvard_relig_compare.png", wd = 6, ht = 10)
cc <- cces %>%
filter(year == 2022) %>%
filter(age == 18) %>%
mutate(rel = frcode(religion == 1 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 3 ~ "Mormon",
religion == 4 ~ "Orthodox",
religion == 5 ~ "Jewish",
religion == 6 ~ "Muslim",
religion == 7 ~ "Buddhist",
religion == 8 ~ "Hindu",
religion == 9 ~ "Atheist",
religion == 10 ~ "Agnostic",
religion == 11 ~ "Nothing in Particular",
religion == 12 ~ "Other")) %>%
ct(rel, wt = weight, show_na = FALSE) %>%
mutate(type = "All 18\nYr. Olds")
both <- bind_rows(cc, harvard)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = reorder(type, pct), y = pct, fill = type)) +
geom_col(color = "black") +
facet_wrap(~ rel) +
scale_y_continuous(labels = percent, limits = c(0, .40)) +
geom_text(aes(y = pct + .03, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 7, family = "font") +
theme_rb() +
scale_fill_gdocs() +
labs(x = "", y = "", title = "Comparing Havard's Freshmen Class With\nAll 18 Year Olds", caption = "@ryanburge\nData: Cooperative Election Study, 2022 + Harvard Crimson's Meet the Class of 2027")
save("harvard_relig_compare_ces.png", wd = 6, ht = 10)
ff <- fire %>%
filter(age == 18) %>%
mutate(prot = case_when(religion == 1 | religion == 12 ~ 1,
TRUE ~ 0)) %>%
# group_by(school) %>%
mean_ci(prot, wt = weight)
low <- ff %>% arrange(mean) %>% head(25)
low %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(school, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_gradient(low = "#5f2c82", high = "#49a09d") +
geom_text(aes(y = mean + .0065, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 6, family = "font") +
labs(x = "", y = "", title = "The 25 Least Protestant Schools in the FIRE Data", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024")
save("least_prot_fire.png", ht = 8)
high <- ff %>% arrange(-mean) %>% head(25)
high %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(school, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_gradient(low = "#FFEDBC", high = "#ED4264") +
geom_text(aes(y = mean + .04, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 6, family = "font") +
labs(x = "", y = "", title = "The 25 Most Protestant Schools in the FIRE Data", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024")
save("most_prot_fire.png", ht = 8)
ff <- fire %>%
mutate(prot = case_when(religion == 9 | religion == 10 ~ 1,
TRUE ~ 0)) %>%
group_by(school) %>%
mean_ci(prot, wt = weight) ## Total Mean is 19%
low <- ff %>% arrange(mean) %>% head(25)
low %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(school, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_gradient(low = "#3D7EAA", high = "#FFE47A") +
geom_text(aes(y = mean + .0065, label = ifelse(mean >= .10, paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 6, family = "font") +
geom_text(aes(y = mean + .005, label = ifelse(mean < .10, paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 6, family = "font") +
labs(x = "", y = "", title = "The 25 Least Atheist/Agnostic Schools in the FIRE Data", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024")
save("least_ath_fire.png", ht = 8)
high <- ff %>% arrange(-mean) %>% head(25)
high %>%
mutate(lab = round(mean, 2)) %>%
ggplot(., aes(x = reorder(school, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
theme_rb() +
y_pct() +
scale_fill_gradient(low = "#F8CDDA", high = "#1D2B64") +
geom_text(aes(y = mean + .02, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 6, family = "font") +
labs(x = "", y = "", title = "The 25 Most Atheist/Agnostic Schools in the FIRE Data", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024")
save("most_ath_fire.png", ht = 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment