Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created December 20, 2024 16:54
Show Gist options
  • Save ryanburge/fb3f5eed8b6f038abcfbe5f31d232e26 to your computer and use it in GitHub Desktop.
Save ryanburge/fb3f5eed8b6f038abcfbe5f31d232e26 to your computer and use it in GitHub Desktop.
fire <- read_csv("E://data/fire2025.csv")
gg <- fire %>%
mutate(hs = case_when(highschool == 4 | highschool == 5 | highschool == 6 ~ 1,
TRUE ~ 0)) %>%
group_by(school) %>%
mean_ci(hs, wt = weight, ci = .84)
one <- gg %>%
arrange(-mean) %>%
head(25) %>%
mutate(cat = "a") %>%
select(school, mean, cat)
two <- fire %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
group_by(school) %>%
ct(hs, wt = weight, show_na = FALSE) %>%
filter(hs == "Parochial" | hs == "Private" | hs == "Home School")
graph <- left_join(one, two) %>% filter(cat == "a")
graph %>%
ggplot(., aes(x = reorder(school, mean), y = pct, fill = fct_rev(hs))) +
geom_col(color = "black") +
coord_flip() +
geom_text(aes(label = ifelse(pct > 0.05, paste0(round(pct * 100, 0), "%"), "")),
position = position_stack(vjust = 0.5),
size = 5,
color = "white", family = "font") +
theme_rb(legend = TRUE) +
y_pct() +
scale_fill_manual(values = c("Parochial" = "#1f78b4",
"Private" = "#ff7f00",
"Home School" = "#33a02c")) +
guides(fill = guide_legend(reverse = TRUE)) +
theme(plot.title = element_text(size = 14)) +
labs(x = "", y = "",
title = "The Colleges with the Highest Share of Students Who Went to Non-Public High Schools",
caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("nonprivate_hs_fire.png", ht = 8)
fire %>%
group_by(school) %>%
ct(highschool) %>%
filter(highschool == 6) %>% arrange(-n)
gg <- fire %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
mutate(attend = religattend) %>%
mutate(attend = frcode(attend == 1 ~ "Never",
attend == 2 ~ "Seldom",
attend == 3 | attend == 4 ~ "Yearly",
attend == 5 | attend == 6 ~ "Monthly",
attend == 7 | attend == 8 | attend == 9 ~ "Weekly")) %>%
group_by(hs) %>%
ct(attend, wt = weight, show_na = FALSE) %>% filter(hs != "NA")
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(attend))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ hs, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c("Weekly" = "#000080",
"Monthly" = "#1E90FF",
"Yearly" = "#6495ED",
"Seldom" = "#ADD8E6",
"Never" = "#D3D3D3")) +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
guides(fill = guide_legend(reverse=T, nrow = 1)) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank()) +
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
geom_text(aes(label = ifelse(attend == "Weekly", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(size = 15, angle = 0, hjust = 1)) +
labs(x = "", y = "", title = "The Religious Attendance of College Students Based on Type of High School Attended", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("fire_att_high_school_type.png", wd = 9, ht = 5)
gg <- fire %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
mutate(relig = frcode(religion == 1 | religion == 10 ~ "Protestant",
religion == 2 ~ "Catholic",
religion == 6 | religion == 11 | religion == 12 | religion == 3 | religion == 4 | religion == 5 ~ "Other World Religions",
religion == 7 | religion == 8 ~ "Atheist/Agnostic",
religion == 9 ~ "Nothing in Particular",
religion == 11 ~ "Other")) %>%
group_by(hs) %>%
ct(relig, wt = weight, show_na = FALSE) %>% filter(hs != "NA")
gg %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(relig))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ hs, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c(
"Protestant" = "#1f78b4",
"Catholic" = "#33a02c",
"Other World Religions" = "#ff7f00",
"Atheist/Agnostic" = "#6a3d9a",
"Nothing in Particular" = "#b2df8a",
"Other" = "#fdbf6f"
)) +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
guides(fill = guide_legend(reverse=T, nrow = 1)) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank()) +
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
geom_text(aes(label = ifelse(relig == "Atheist/Agnostic", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
geom_text(aes(label = ifelse(relig == "Catholic", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
geom_text(aes(label = ifelse(relig == "Protestant", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(size = 15, angle = 0, hjust = 1)) +
labs(x = "", y = "", title = "The Religious Composition of College Students Based on Type of High School Attended", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("fire_relig_high_school_type.png", wd = 9, ht = 5)
gg1 <- fire %>%
filter(partyid <= 7) %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
group_by(hs) %>%
mean_ci(partyid, wt = weight) %>% filter(hs != "NA") %>%
select(hs, pid = mean)
gg2 <- fire %>%
mutate(ideo = case_when(ideo == 1 ~ 1,
ideo == 2 ~ 2,
ideo == 3 ~ 3,
ideo == 4 ~ 4,
ideo == 5 ~ 5,
ideo == 7 ~ 6,
ideo == 8 ~ 7)) %>%
filter(ideo <= 7) %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
group_by(hs) %>%
mean_ci(ideo, wt = weight) %>% filter(hs != "NA") %>%
select(hs, id = mean, n)
both <- left_join(gg1, gg2)
library(ggrepel)
both %>%
ggplot(., aes(x = pid, y = id)) +
geom_point(aes(color = hs, size = n), stroke = 1, shape = 21) +
scale_color_manual(values = c(met.brewer("Austria", 6))) +
scale_y_continuous(
breaks = 1:7,
limits = c(2.5,4.25),
labels = c("Very Liberal", "Liberal", "Somewhat Liberal", "Middle of the Road", "Somewhat Conservative", "Conservative", "Very Conservative")
) +
scale_x_continuous(
breaks = 1:7,
limits = c(2.75,4.5),
labels = c("Strong\nDem.", "Not Strong\nDem.", "Lean\nDem.", "Independent", "Lean\nRep.", "Not Strong\nRep.", "Strong\nRep.")
) +
theme_rb() +
geom_text_repel(data = both, aes(x = pid, y = id, label = hs), family = "font", size = 5) +
labs(x = "Mean Political Partisanship", y = "Mean Political Ideology", title = "College Students in Ideological and Partisan Space by Type of High School Attended",
caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("fire2025_scatter_pid_id_highschool.png")
gg <- fire %>%
filter(religion == 1 | religion == 2 | religion == 10 | religion == 3 | religion == 4) %>%
mutate(id7 = ideo) %>%
mutate(id7 = frcode(id7 == 1 ~ "Very Liberal",
id7 == 2 ~ "Somewhat Liberal",
id7 == 3 ~ "Slightly Liberal",
id7 == 4 ~ "Middle of the Road",
id7 == 5 ~ "Slightly Cons.",
id7 == 7 ~ "Somewhat Cons.",
id7 == 8 ~ "Very Cons.")) %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
group_by(hs) %>%
ct(id7, wt = weight, show_na = FALSE)
gg %>%
filter(hs != "NA") %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(id7))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ hs, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c(
"Very Liberal" = "#1f78b4", # Dark Blue
"Somewhat Liberal" = "#a6cee3", # Light Blue
"Slightly Liberal" = "#b2df8a", # Light Green
"Middle of the Road" = "#ffdb58", # Yellow
"Slightly Cons." = "#fdae61", # Light Orange
"Somewhat Cons." = "#f46d43", # Orange
"Very Cons." = "#d73027" # Dark Red
)) +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
guides(fill = guide_legend(reverse=T, nrow = 1)) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank()) +
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
geom_text(aes(label = ifelse(pct >.05 & id7 == "Very Liberal", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(size = 15, angle = 0, hjust = 1)) +
theme(legend.text = element_text(size = 9)) +
labs(x = "", y = "", title = "The Political Ideology of Christian College Students by Type of High School They Attended", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("fire25_hs_type_xtn_id7.png", wd = 10, ht = 5)
gg1 <- fire %>%
# filter(religion == 1 | religion == 2 | religion == 10 | religion == 3 | religion == 4) %>%
mutate(id7 = ideo) %>%
mutate(id7 = frcode(id7 == 1 ~ "Very Liberal",
id7 == 2 ~ "Somewhat Liberal",
id7 == 3 ~ "Slightly Liberal",
id7 == 4 ~ "Middle of the Road",
id7 == 5 ~ "Slightly Cons.",
id7 == 7 ~ "Somewhat Cons.",
id7 == 8 ~ "Very Cons.")) %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
# group_by(hs) %>%
ct(id7, wt = weight, show_na = FALSE) %>%
mutate(type = "All College Students")
gg2 <- fire %>%
filter(religion == 1 | religion == 2 | religion == 10 | religion == 3 | religion == 4) %>%
mutate(id7 = ideo) %>%
mutate(id7 = frcode(id7 == 1 ~ "Very Liberal",
id7 == 2 ~ "Somewhat Liberal",
id7 == 3 ~ "Slightly Liberal",
id7 == 4 ~ "Middle of the Road",
id7 == 5 ~ "Slightly Cons.",
id7 == 7 ~ "Somewhat Cons.",
id7 == 8 ~ "Very Cons.")) %>%
mutate(hs = frcode(highschool == 1 ~ "Public",
highschool == 2 ~ "Public Charter",
highschool == 3 ~ "Public Magnet",
highschool == 4 ~ "Parochial",
highschool == 5 ~ "Private",
highschool == 6 ~ "Home School")) %>%
# group_by(hs) %>%
ct(id7, wt = weight, show_na = FALSE) %>%
mutate(type = "Christian College Students")
both <- bind_rows(gg1, gg2)
both %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(id7))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ type, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c(
"Very Liberal" = "#1f78b4", # Dark Blue
"Somewhat Liberal" = "#a6cee3", # Light Blue
"Slightly Liberal" = "#b2df8a", # Light Green
"Middle of the Road" = "#ffdb58", # Yellow
"Slightly Cons." = "#fdae61", # Light Orange
"Somewhat Cons." = "#f46d43", # Orange
"Very Cons." = "#d73027" # Dark Red
)) +
theme(legend.position = "bottom") +
scale_y_continuous(labels = percent) +
theme(strip.text.y.left = element_text(angle=0)) +
guides(fill = guide_legend(reverse=T, nrow = 1)) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(panel.grid.minor.y=element_blank(), panel.grid.major.y=element_blank()) +
geom_text(aes(label = ifelse(pct >.05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") +
geom_text(aes(label = ifelse(pct >.05 & id7 == "Very Liberal", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") +
theme(plot.title = element_text(size = 16)) +
theme(strip.text.y.left = element_text(size = 15, angle = 0, hjust = 1)) +
theme(legend.text = element_text(size = 9)) +
labs(x = "", y = "", title = "The Political Ideology of College Students", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2025")
save("fire25__xtn_id7.png", wd = 10, ht = 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment