-
-
Save ryanburge/116cc035155c4e200e1394da90a0d438 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fire <- read_csv("E://data/fire24.csv") | |
fire <- fire %>% | |
mutate(rel = frcode(religion == 1 ~ "Protestant", | |
religion == 2 ~ "Catholic", | |
religion == 3 ~ "LDS", | |
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 ~ "Just Christian", | |
religion == 13 ~ "Other")) | |
fun <- function(var, name){ | |
fire %>% | |
mutate(vv = {{var}}) %>% | |
mean_ci(vv, wt = weight, ci = .84) %>% | |
mutate(type = name) | |
} | |
var <- syms(c("asiangrp", "atheistgrp", "gopgrp", "demgrp", "consgrp", "libgrp", "blmgrp", "israelgrp", "palestinegrp", "blkgrp", "hispgrp", "greekgrp", "lgbtqgrp", "christgrp", "jewgrp", "islamgrp", "hindugrp")) | |
name <- c("Asian", "Atheist", "Republican", "Democrat", "Conservative", "Liberal", "Black Lives Matter", "Pro-Israeli", "Pro-Palestinian", "African-American", "Hispanic", "Sorority/Fraternity", "LGBTQ+", "Christian", "Jewish", "Muslim", "Hindu") | |
gg <- map2_df(var, name, fun, .progress = TRUE) | |
gg %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(., aes(x = reorder(type, mean), y = mean, fill = type)) + | |
geom_col(color = "black") + | |
coord_flip() + | |
theme_rb() + | |
error_bar() + | |
y_pct() + | |
scale_fill_manual(values = c(moma.colors("Warhol", 17))) + | |
lab_bar(top = FALSE, type = lab, pos = .03, sz = 6) + | |
labs(x = "", y = "Share Saying Yes", title = "Which of the following groups on your campus should be able to register as student\norganizations and receive student activity fees?", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024") | |
save("student_group_all.png") | |
fire$sum = rowSums(fire[, c("asiangrp", "atheistgrp", "gopgrp", "demgrp", "consgrp", "libgrp", "blmgrp", "israelgrp", "palestinegrp", "blkgrp", "hispgrp", "greekgrp", "lgbtqgrp", "christgrp", "jewgrp", "islamgrp", "hindugrp")], na.rm = TRUE) | |
graph <- fire %>% | |
group_by(rel) %>% | |
mean_ci(sum, wt = weight, ci = .84) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x = reorder(rel, mean), y = mean, color = rel)) + | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=0, position=position_dodge(.9), linewidth = 1) + | |
geom_point(stroke = 1, shape = 21, fill = "white", size = 4) + | |
coord_flip() + | |
theme_rb() + | |
geom_hline(yintercept = 10.2, linetype = "twodash") + | |
scale_color_manual(values = c(met.brewer("Johnson", 13))) + | |
add_text(y = 9.75, x = 12.5, word = "Avg: 10.2", sz = 6) + | |
labs(x = "", y = "", title = "Average Number of Groups Respondent Approved Of - Max is 17", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024") | |
save("number_clubs_support.png", ht = 5) | |
fun <- function(var, name){ | |
aa1 <- fire %>% | |
filter(rel == "Atheist" | rel == "Agnostic") %>% | |
mutate(vv = {{var}}) %>% | |
mean_ci(vv, wt = weight, ci = .84) %>% | |
mutate(type = name) %>% | |
mutate(grp = "Atheist/\nAgnostic") | |
aa2 <- fire %>% | |
filter(rel == "Protestant" | rel == "Catholic" | rel == "Just Christian" | rel == "Orthodox") %>% | |
mutate(vv = {{var}}) %>% | |
mean_ci(vv, wt = weight, ci = .84) %>% | |
mutate(type = name) %>% | |
mutate(grp = "Christian") | |
bind_rows(aa1, aa2) | |
} | |
var <- syms(c("asiangrp", "atheistgrp", "gopgrp", "demgrp", "consgrp", "libgrp", "blmgrp", "israelgrp", "palestinegrp", "blkgrp", "hispgrp", "greekgrp", "lgbtqgrp", "christgrp", "jewgrp", "islamgrp", "hindugrp")) | |
name <- c("Asian", "Atheist", "Republican", "Democrat", "Conservative", "Liberal", "Black Lives Matter", "Pro-Israeli", "Pro-Palestinian", "African-American", "Hispanic", "Sorority/Fraternity", "LGBTQ+", "Christian", "Jewish", "Muslim", "Hindu") | |
gg <- map2_df(var, name, fun, .progress = TRUE) | |
gg %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(aes(x = grp, y = mean, fill = grp)) + | |
geom_col(color = "black") + | |
facet_wrap(~ type) + | |
scale_fill_calc() + | |
y_pct() + | |
error_bar() + | |
theme_rb() + | |
theme(legend.position = c(.7, .10), legend.direction = "horizontal") + | |
theme(legend.text = element_text(size = 20)) + | |
geom_text(aes(y = .1, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 9, family = "font") + | |
geom_text(aes(y = .1, label = ifelse(grp == "Atheist/\nAgnostic", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 9, family = "font", color = "white") + | |
labs(x = "", y = "Share Saying Yes", title = "Which of the following groups on your campus should be able to register as student\norganizations and receive student activity fees?" , caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024") | |
save("xtn_ath_grp_compare.png", ht = 10) | |
fire %>% | |
mutate(id3 = frcode(ideo == 1 | ideo == 2 | ideo == 3 ~ "Liberal", | |
ideo == 4 ~ "Moderate", | |
ideo == 5 | ideo == 6 | ideo == 7 ~ "Conservative")) %>% | |
group_by(id3) %>% | |
mean_ci(sum, wt = weight, ci = .84) %>% | |
na.omit() | |
# id3 mean sd n se lower upper | |
# <fct> <dbl> <dbl> <int> <dbl> <dbl> <dbl> | |
# 1 Liberal 11.6 6.26 28047 0.0374 11.5 11.6 | |
# 2 Moderate 9.49 7.27 7738 0.0826 9.38 9.61 | |
# 3 Conservative 8.98 7.26 10412 0.0712 8.89 9.09 | |
fun <- function(var, name){ | |
aa1 <- fire %>% | |
filter(rel == "Atheist" | rel == "Agnostic") %>% | |
mutate(vv = {{var}}) %>% | |
mutate(id3 = frcode(ideo == 1 | ideo == 2 | ideo == 3 ~ "Liberal", | |
ideo == 4 ~ "Mod.", | |
ideo == 5 | ideo == 6 | ideo == 7 ~ "Cons.")) %>% | |
group_by(id3) %>% | |
mean_ci(vv, wt = weight, ci = .84) %>% | |
mutate(type = name) %>% | |
mutate(grp = "Atheist/\nAgnostic") | |
aa2 <- fire %>% | |
filter(rel == "Protestant" | rel == "Catholic" | rel == "Just Christian" | rel == "Orthodox") %>% | |
mutate(vv = {{var}}) %>% | |
mutate(id3 = frcode(ideo == 1 | ideo == 2 | ideo == 3 ~ "Liberal", | |
ideo == 4 ~ "Mod.", | |
ideo == 5 | ideo == 6 | ideo == 7 ~ "Cons.")) %>% | |
group_by(id3) %>% | |
mean_ci(vv, wt = weight, ci = .84) %>% | |
mutate(type = name) %>% | |
mutate(grp = "Christian") | |
bind_rows(aa1, aa2) %>% na.omit() | |
} | |
var <- syms(c("asiangrp", "atheistgrp", "gopgrp", "demgrp", "consgrp", "libgrp", "blmgrp", "israelgrp", "palestinegrp", "blkgrp", "hispgrp", "greekgrp", "lgbtqgrp", "christgrp", "jewgrp", "islamgrp", "hindugrp")) | |
name <- c("Asian", "Atheist", "Republican", "Democrat", "Conservative", "Liberal", "Black Lives Matter", "Pro-Israeli", "Pro-Palestinian", "African-American", "Hispanic", "Sorority/Fraternity", "LGBTQ+", "Christian", "Jewish", "Muslim", "Hindu") | |
gg <- map2_df(var, name, fun, .progress = TRUE) | |
gg %>% | |
mutate(lab = round(mean, 2)) %>% | |
ggplot(aes(x = id3, y = mean, fill = grp)) + | |
geom_col(color = "black", position = "dodge") + | |
facet_wrap(~ type) + | |
scale_fill_calc() + | |
y_pct() + | |
error_bar() + | |
theme_rb() + | |
theme(legend.position = c(.7, .08), legend.direction = "horizontal") + | |
theme(legend.text = element_text(size = 20)) + | |
geom_text(aes(y = .075, label = paste0(lab*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") + | |
geom_text(aes(y = .075, label = ifelse(grp == "Atheist/\nAgnostic", paste0(lab*100, '%'), "")), position = position_dodge(width = .9), size = 3, family = "font", color = "white") + | |
labs(x = "", y = "Share Saying Yes", title = "Which of the following groups on your campus should be able to register as student\norganizations and receive student activity fees?" , caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024") | |
save("xtn_ath_grp_compare_id3.png", ht = 10) | |
graph <- fire %>% | |
mutate(id3 = frcode(ideo == 1 | ideo == 2 | ideo == 3 ~ "Liberal", | |
ideo == 4 ~ "Moderate", | |
ideo == 5 | ideo == 6 | ideo == 7 ~ "Conservative")) %>% | |
group_by(rel, id3) %>% | |
mean_ci(sum, wt = weight, ci = .84) %>% | |
na.omit() | |
graph %>% | |
ggplot(., aes(x = reorder(rel, mean), y = mean, color = id3)) + | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=0) + | |
geom_point(stroke = 1, shape = 21, fill = "white", size = 4) + | |
pid3_color() + | |
coord_flip() + | |
theme_rb(legend = TRUE) + | |
labs(x = "", y = "", title = "Average Number of Groups Respondent Approved Of - Max is 17", caption = "@ryanburge\nData: FIRE Free Speech Rankings, 2024") | |
save("number_clubs_support_id3.png", ht = 5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment