-
-
Save ryanburge/87ee44d46db2d1e065d18be0a2081ff6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| library(janitor) | |
| mean <- read_csv("E://data/meaning.csv") %>% clean_names() | |
| ## rename #### | |
| mean <- mean %>% | |
| rename(relig = q94) %>% | |
| rename(birthyr = q505) %>% | |
| rename(gender = q4) %>% | |
| rename(race = q6) %>% | |
| rename(hisp = q506) %>% | |
| rename(relig16 = q502) %>% | |
| rename(state = q28) %>% | |
| rename(most_rel_age = q55_1) %>% | |
| rename(most_rel_score = q89_1) %>% | |
| rename(now_rel_score = q89_2) %>% | |
| rename(most_rel_behave = q90_1) %>% | |
| rename(now_rel_behave = q90_2) %>% | |
| rename(attend = q70) %>% | |
| rename(prayer = q71) %>% | |
| rename(religimp = q72) %>% | |
| rename(spiritimp = q138) %>% | |
| rename(maattend = q129) %>% | |
| rename(paattend = q130) %>% | |
| rename(marel = q131) %>% | |
| rename(parel = q132) %>% | |
| rename(ev_now = q125) %>% | |
| rename(ev_ever = q74) %>% | |
| rename(ev_ma = q127) %>% | |
| rename(ev_pa = q128) %>% | |
| rename(life_sat = q250_1) %>% | |
| rename(mtf_1 = q68_1) %>% | |
| rename(mtf_2 = q68_2) %>% | |
| rename(mtf_3 = q68_3) %>% | |
| rename(mtf_4 = q68_4) %>% | |
| rename(mtf_5 = q68_5) %>% | |
| rename(mtf_6 = q68_6) %>% | |
| rename(mtf_7 = q68_7) %>% | |
| rename(mtf_8 = q68_8) %>% | |
| rename(mtf_9 = q68_9) %>% | |
| rename(mtf_10 = q68_10) %>% | |
| rename(mtf_11 = q68_11) %>% | |
| rename(mtf_12 = q68_12) %>% | |
| rename(mtf_13 = q68_13) %>% | |
| rename(mtf_14 = q68_14) %>% | |
| rename(sec_aff1 = q53_1) %>% | |
| rename(sec_aff2 = q53_2) %>% | |
| rename(sec_aff3 = q53_3) %>% | |
| rename(sec_aff4 = q53_4) %>% | |
| rename(sec_aff5 = q53_5) %>% | |
| rename(sec_reject1 = q54_1) %>% | |
| rename(sec_reject2 = q54_2) %>% | |
| rename(sec_reject3 = q54_3) %>% | |
| rename(sp_person = q136) %>% | |
| rename(rel_person = q137) %>% | |
| rename(rel_pur1 = q46_1) %>% | |
| rename(rel_pur2 = q46_2) %>% | |
| rename(rel_pur3 = q46_3) %>% | |
| rename(sp_pur1 = q47_1) %>% | |
| rename(sp_pur2 = q47_2) %>% | |
| rename(sp_pur3 = q47_3) %>% | |
| rename(after1 = q48_1) %>% | |
| rename(after2 = q48_2) %>% | |
| rename(after3 = q48_3) %>% | |
| rename(after4 = q48_4) %>% | |
| rename(after5 = q48_5) %>% | |
| rename(after6 = q48_6) %>% | |
| rename(justice1 = q49_1) %>% | |
| rename(justice2 = q49_2) %>% | |
| rename(justice3 = q49_3) %>% | |
| rename(justice4 = q49_4) %>% | |
| rename(justice5 = q49_5) %>% | |
| rename(s_act = q50) %>% | |
| rename(rank_health = q51_1) %>% | |
| rename(rank_mental = q51_2) %>% | |
| rename(rank_emotion = q51_3) %>% | |
| rename(rank_spirit = q51_4) %>% | |
| rename(rank_social = q51_5) %>% | |
| rename(rank_intell = q51_6) %>% | |
| rename(rank_money = q51_7) %>% | |
| rename(spirit1 = q52_1) %>% | |
| rename(spirit2 = q52_2) %>% | |
| rename(spirit3 = q52_3) %>% | |
| rename(spirit4 = q52_4) %>% | |
| rename(spirit5 = q52_5) %>% | |
| rename(sp_item = q139) %>% | |
| rename(leave_rel = q126) %>% | |
| rename(per_trust = q41) %>% | |
| rename(tr_comp = q42_1) %>% | |
| rename(tr_relig = q42_2) %>% | |
| rename(tr_educ = q42_3) %>% | |
| rename(tr_pres = q42_4) %>% | |
| rename(tr_labor = q42_5) %>% | |
| rename(tr_media = q42_6) %>% | |
| rename(tr_medicine = q42_7) %>% | |
| rename(tr_tech = q42_8) %>% | |
| rename(tr_scotus = q42_9) %>% | |
| rename(tr_science = q42_10) %>% | |
| rename(tr_congress = q42_11) %>% | |
| rename(tr_mili = q42_12) %>% | |
| rename(tr_banks = q42_13) %>% | |
| rename(polpart = q43) %>% | |
| rename(some1 = q44_1) %>% | |
| rename(some2 = q44_2) %>% | |
| rename(some3 = q44_3) %>% | |
| rename(some4 = q44_4) %>% | |
| rename(some5 = q44_5) %>% | |
| rename(some6 = q44_6) %>% | |
| rename(some7 = q44_7) %>% | |
| rename(some8 = q44_8) %>% | |
| rename(some9 = q44_9) %>% | |
| rename(some10 = q44_10) %>% | |
| rename(some11 = q44_11) %>% | |
| rename(some12 = q44_12) %>% | |
| rename(some13 = q44_13) %>% | |
| rename(some14 = q44_14) %>% | |
| rename(some15 = q44_15) %>% | |
| rename(some16 = q44_16) %>% | |
| rename(some17 = q44_17) %>% | |
| rename(some18 = q44_18) %>% | |
| rename(some19 = q44_19) %>% | |
| rename(some20 = q44_20) %>% | |
| rename(some21 = q44_21) %>% | |
| rename(embryo1 = q82_1) %>% | |
| rename(embryo2 = q82_2) %>% | |
| rename(embryo3 = q82_3) %>% | |
| rename(soul1 = q83_1) %>% | |
| rename(soul2 = q83_2) %>% | |
| rename(soul3 = q83_3) %>% | |
| rename(soul4 = q83_4) %>% | |
| rename(soul5 = q83_5) %>% | |
| rename(soul6 = q83_6) %>% | |
| rename(read_scrip = q84) %>% | |
| rename(relorient1 = q85_1) %>% | |
| rename(relorient2 = q85_2) %>% | |
| rename(relorient3 = q85_3) %>% | |
| rename(relorient4 = q85_4) %>% | |
| rename(relknow1 = q86_1) %>% | |
| rename(relknow2 = q86_2) %>% | |
| rename(relknow3 = q86_3) %>% | |
| rename(relknow4 = q86_4) %>% | |
| rename(relknow5 = q86_5) %>% | |
| rename(relknow6 = q86_6) %>% | |
| rename(relknow7 = q86_7) %>% | |
| rename(relknow8 = q86_8) %>% | |
| rename(relknow9 = q86_9) %>% | |
| rename(relknow10 = q86_10) %>% | |
| rename(relbad1 = q87_1) %>% | |
| rename(relbad2 = q87_2) %>% | |
| rename(relbad3 = q87_3) %>% | |
| rename(relbad4 = q87_4) %>% | |
| rename(relbad5 = q87_5) %>% | |
| rename(relbad6 = q87_6) %>% | |
| rename(b_after = q88_1) %>% | |
| rename(b_heaven = q88_2) %>% | |
| rename(b_hell = q88_3) %>% | |
| rename(b_miracles = q88_4) %>% | |
| rename(b_reincarn = q88_5) %>% | |
| rename(b_nivrana = q88_6) %>% | |
| rename(b_angels = q88_7) %>% | |
| rename(b_ghosts = q88_8) %>% | |
| rename(b_prayer = q88_9) %>% | |
| rename(b_crystals = q88_10) %>% | |
| rename(b_ancestor = q88_11) %>% | |
| rename(gay_refuse = q78) %>% | |
| rename(twogen = q150_1) %>% | |
| rename(porn = q150_2) %>% | |
| rename(cas_sex = q150_3) %>% | |
| rename(hard_drugs = q150_4) %>% | |
| rename(sex_work = q150_5) %>% | |
| rename(imp_emotion = q118_1) %>% | |
| rename(imp_spirit = q118_2) %>% | |
| rename(imp_mood = q118_3) %>% | |
| rename(take_time = q118_4) %>% | |
| rename(dislike_more = q118_5) %>% | |
| rename(pol_involve = q118_6) %>% | |
| rename(tolerant = q118_7) %>% | |
| rename(rel_discrim = q119_1) %>% | |
| rename(burqa = q119_2) %>% | |
| rename(mili_hat = q119_3) %>% | |
| rename(pres_faith = q36_1) %>% | |
| rename(pol_trust_faith = q36_2) %>% | |
| rename(moral_foundation = q36_3) %>% | |
| rename(rel_extreme = q36_4) %>% | |
| rename(ath_pol = q36_5) %>% | |
| rename(belief_god = q38) %>% | |
| rename(school_prayer = q40_1) %>% | |
| rename(school_med = q40_2) %>% | |
| rename(school_pledge = q40_3) %>% | |
| rename(school_grad = q40_4) %>% | |
| rename(therm_ev = q77_1) %>% | |
| rename(therm_lds = q77_2) %>% | |
| rename(therm_jew = q77_3) %>% | |
| rename(therm_muslim = q77_4) %>% | |
| rename(therm_atheist = q77_5) %>% | |
| rename(therm_trans = q77_6) %>% | |
| rename(therm_lgb = q77_7) %>% | |
| rename(therm_dems = q77_8) %>% | |
| rename(therm_gop = q77_9) %>% | |
| rename(therm_me = q77_10) %>% | |
| rename(vote_reg = q32) %>% | |
| rename(vote2020 = q33) %>% | |
| rename(vote2024 = q142) %>% | |
| rename(ideo7 = q76) %>% | |
| rename(pid7 = q34) %>% | |
| rename(media_consume = q35) %>% | |
| rename(home_life = q26) %>% | |
| rename(home_state = q29) %>% | |
| rename(home_geo = q30) %>% | |
| rename(now_geo = q31) %>% | |
| rename(income = q16) %>% | |
| rename(inc_change = q17) %>% | |
| rename(inc_future = q18) %>% | |
| rename(inc_kid = q19) %>% | |
| rename(employ = q12) %>% | |
| rename(hours_work = q13) %>% | |
| rename(industry = q14) %>% | |
| rename(military = q15) %>% | |
| rename(marital = q7) %>% | |
| rename(divorce = q124) %>% | |
| rename(marry_faith = q135_1) %>% | |
| rename(age_marry = q7_a) %>% | |
| rename(bgender = q2) %>% | |
| rename(trans = q3) %>% | |
| rename(sexorient = q5) %>% | |
| rename(parent = q8) %>% | |
| rename(numkids = q9) %>% | |
| rename(immstat = q11) %>% | |
| rename(age_parent = q8_a) %>% | |
| rename(educ = q20) %>% | |
| rename(educpa = q21) %>% | |
| rename(educma = q22) %>% | |
| rename(rel_school = q23) %>% | |
| rename(major = q20_a) %>% | |
| rename(alcohol = q145_1) %>% | |
| rename(nictone = q145_2) %>% | |
| rename(weed = q145_3) %>% | |
| rename(gummy = q145_4) %>% | |
| rename(heroin = q145_5) %>% | |
| rename(cocaine = q145_6) %>% | |
| rename(lsd = q145_7) %>% | |
| rename(twitter = q146_1) %>% | |
| rename(facebook = q146_2) %>% | |
| rename(tiktok = q146_3) %>% | |
| rename(instagram = q146_4) %>% | |
| rename(snapchat = q146_5) %>% | |
| rename(youtube = q146_6) %>% | |
| rename(linkedin = q146_7) %>% | |
| rename(reddit = q146_8) %>% | |
| rename(pinterest = q146_9) %>% | |
| rename(threads = q146_10) | |
| mean %>% | |
| ct(relig) | |
| cces24 %>% | |
| mutate(relig = frcode(religpew == 1 ~ "Protestant", | |
| religpew == 2 ~ "Catholic", | |
| religpew == 3 ~ "Mormon", | |
| religpew == 4 ~ "Orthodox", | |
| religpew == 5 ~ "Jewish", | |
| religpew == 6 ~ "Muslim", | |
| religpew == 7 ~ "Buddhist", | |
| religpew == 8 ~ "Hindu", | |
| religpew == 9 ~ "Atheist", | |
| religpew == 10 ~ "Agnostic", | |
| religpew == 11 ~ "Nothing in Particular", | |
| religpew == 12 ~ "Something Else")) %>% | |
| ct(relig, wt = commonweight, show_na = FALSE) | |
| mean <- mean %>% | |
| mutate(relig = case_when( | |
| relig == "Roman Catholic" ~ "Catholic", | |
| relig == "Eastern or Greek Orthodox" ~ "Orthodox", | |
| TRUE ~ relig | |
| )) | |
| target <- tribble( | |
| ~relig, ~target_pct, | |
| "Protestant", 0.335, | |
| "Catholic", 0.178, | |
| "Mormon", 0.011, | |
| "Orthodox", 0.006, | |
| "Jewish", 0.022, | |
| "Muslim", 0.008, | |
| "Buddhist", 0.009, | |
| "Hindu", 0.005, | |
| "Atheist", 0.067, | |
| "Agnostic", 0.063, | |
| "Nothing in particular", 0.212, | |
| "Something else", 0.084 | |
| ) | |
| obs <- mean %>% | |
| mutate(relig = case_when( | |
| relig == "Roman Catholic" ~ "Catholic", | |
| relig == "Eastern or Greek Orthodox" ~ "Orthodox", | |
| TRUE ~ relig | |
| )) %>% | |
| count(relig, name = "n") %>% | |
| mutate(obs_pct = n / sum(n)) | |
| weights <- obs %>% | |
| left_join(target, by = "relig") %>% | |
| mutate(wt = target_pct / obs_pct) | |
| mean <- mean %>% | |
| left_join(weights %>% select(relig, wt), by = "relig") | |
| mean <- mean %>% | |
| mutate(wt = wt / mean(wt, na.rm = TRUE)) | |
| mean <- mean %>% | |
| mutate(pres_faith = frcode( | |
| pres_faith == "Strongly disagree" ~ "Strongly Disagree", | |
| pres_faith == "Somewhat disagree" ~ "Somewhat Disagree", | |
| pres_faith == "Neither agree nor disagree" ~ "Neutral", | |
| pres_faith == "Somewhat agree" ~ "Somewhat Agree", | |
| pres_faith == "Strongly agree" ~ "Strongly Agree" | |
| )) | |
| gg1 <- mean %>% | |
| ct(pres_faith, wt = wt) %>% | |
| mutate(relig_grouped = "Entire Sample") | |
| gg2 <- mean %>% | |
| mutate(relig_grouped = case_when( | |
| relig %in% c("Hindu", "Muslim", "Orthodox", "Mormon", "Buddhist") ~ "Other Faith", | |
| TRUE ~ relig | |
| )) %>% | |
| group_by(relig_grouped) %>% | |
| ct(pres_faith, wt = wt) | |
| both <- bind_rows(gg1, gg2) | |
| order_levels <- both %>% | |
| filter(pres_faith %in% c("Somewhat Agree", "Strongly Agree")) %>% | |
| group_by(relig_grouped) %>% | |
| summarize(agree_total = sum(pct)) %>% | |
| mutate(order = rank(-agree_total)) %>% | |
| mutate(order = if_else(relig_grouped == "Entire Sample", 0, order + 1)) %>% | |
| arrange(order) %>% | |
| pull(relig_grouped) | |
| both <- both %>% | |
| mutate(relig_grouped = factor(relig_grouped, levels = order_levels)) | |
| both %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(., aes(x = 1, y = pct, fill = fct_rev(pres_faith))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ relig_grouped, ncol =1, strip.position = "left") + | |
| theme_rb() + | |
| theme(legend.position = "bottom") + | |
| scale_fill_manual(values = c( | |
| "Strongly Disagree" = "#4D4D4D", | |
| "Somewhat Disagree" = "#8C8C47", | |
| "Neutral" = "#E2B007", | |
| "Somewhat Agree" = "#7FB77E", | |
| "Strongly Agree" = "#2E8B8B" | |
| )) + | |
| 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 >.06, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "black") + | |
| geom_text(aes(label = ifelse(pres_faith == "Strongly Disagree" & pct > .05, paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 8, family = "font", color = "white") + | |
| # geom_text(aes(label = ifelse(age2 == "36-44", paste0(lab*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "white") + | |
| theme(plot.title = element_text(size = 16)) + | |
| theme(strip.text.y.left = element_text(angle = 0, hjust = 1)) + | |
| labs(x = "", y = "", title = "I prefer if the President is a person of faith.", caption = "@ryanburge + @jonestony | Data: Making Meaning Survey, 2024") | |
| save("pres_faith_all_trads.png", wd = 9, ht = 5) | |
| mean <- mean %>% | |
| mutate(pol_trust_faith_f = frcode( | |
| pol_trust_faith == "Strongly disagree" ~ "Strongly Disagree", | |
| pol_trust_faith == "Somewhat disagree" ~ "Somewhat Disagree", | |
| pol_trust_faith == "Neither agree nor disagree" ~ "Neutral", | |
| pol_trust_faith == "Somewhat agree" ~ "Somewhat Agree", | |
| pol_trust_faith == "Strongly agree" ~ "Strongly Agree" | |
| )) | |
| gg1 <- mean %>% | |
| ct(pol_trust_faith_f, wt = wt) %>% | |
| mutate(relig_grouped = "Entire Sample") | |
| gg2 <- mean %>% | |
| mutate(relig_grouped = case_when( | |
| relig %in% c("Hindu", "Muslim", "Orthodox", "Mormon", "Buddhist") ~ "Other Faith", | |
| TRUE ~ relig | |
| )) %>% | |
| group_by(relig_grouped) %>% | |
| ct(pol_trust_faith_f, wt = wt) | |
| both <- bind_rows(gg1, gg2) | |
| order_levels <- both %>% | |
| filter(pol_trust_faith_f %in% c("Somewhat Agree", "Strongly Agree")) %>% | |
| group_by(relig_grouped) %>% | |
| summarize(agree_total = sum(pct)) %>% | |
| mutate(order = rank(-agree_total)) %>% | |
| mutate(order = if_else(relig_grouped == "Entire Sample", 0, order + 1)) %>% | |
| arrange(order) %>% | |
| pull(relig_grouped) | |
| both <- both %>% | |
| mutate(relig_grouped = factor(relig_grouped, levels = order_levels)) | |
| both %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(aes(x = 1, y = pct, fill = fct_rev(pol_trust_faith_f))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ relig_grouped, ncol = 1, strip.position = "left") + | |
| theme_rb() + | |
| theme(legend.position = "bottom") + | |
| scale_y_continuous(labels = scales::percent_format()) + | |
| theme(strip.text.y.left = element_text(angle = 0)) + | |
| guides(fill = guide_legend(reverse = TRUE, nrow = 1)) + | |
| theme( | |
| axis.title.y = element_blank(), | |
| axis.text.y = element_blank(), | |
| axis.ticks.y = element_blank(), | |
| panel.grid.minor.y = element_blank(), | |
| panel.grid.major.y = element_blank(), | |
| plot.title = element_text(size = 16), | |
| strip.text.y.left = element_text(angle = 0, hjust = 1) | |
| ) + | |
| 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 & pol_trust_faith_f == "Strongly Disagree", paste0(lab * 100, '%'), '')), | |
| position = position_stack(vjust = 0.5), | |
| size = 8, family = "font", color = "white") + | |
| scale_fill_manual(values = c( | |
| "Strongly Disagree" = "#4D4D4D", | |
| "Somewhat Disagree" = "#8C8C47", | |
| "Neutral" = "#E2B007", | |
| "Somewhat Agree" = "#7FB77E", | |
| "Strongly Agree" = "#2E8B8B" | |
| )) + | |
| labs( | |
| x = "", y = "", | |
| title = "I believe that a politician is more trustworthy if they are a person of faith.", | |
| caption = "@ryanburge + @jonestony | Data: Making Meaning Survey, 2024" | |
| ) | |
| save("trust_pol_faith.png", wd = 9, ht = 5) | |
| mean <- mean %>% | |
| mutate(ath_pol_f = frcode( | |
| ath_pol == "Strongly disagree" ~ "Strongly Disagree", | |
| ath_pol == "Somewhat disagree" ~ "Somewhat Disagree", | |
| ath_pol == "Neither agree nor disagree" ~ "Neutral", | |
| ath_pol == "Somewhat agree" ~ "Somewhat Agree", | |
| ath_pol == "Strongly agree" ~ "Strongly Agree" | |
| )) | |
| gg1 <- mean %>% | |
| ct(ath_pol_f, wt = wt) %>% | |
| mutate(relig_grouped = "Entire Sample") | |
| gg2 <- mean %>% | |
| mutate(relig_grouped = case_when( | |
| relig %in% c("Hindu", "Muslim", "Orthodox", "Mormon", "Buddhist") ~ "Other Faith", | |
| TRUE ~ relig | |
| )) %>% | |
| group_by(relig_grouped) %>% | |
| ct(ath_pol_f, wt = wt) | |
| both <- bind_rows(gg1, gg2) | |
| order_levels <- both %>% | |
| filter(ath_pol_f %in% c("Somewhat Agree", "Strongly Agree")) %>% | |
| group_by(relig_grouped) %>% | |
| summarize(agree_total = sum(pct)) %>% | |
| mutate(order = rank(-agree_total)) %>% | |
| mutate(order = if_else(relig_grouped == "Entire Sample", 0, order + 1)) %>% | |
| arrange(order) %>% | |
| pull(relig_grouped) | |
| both <- both %>% | |
| mutate(relig_grouped = factor(relig_grouped, levels = order_levels)) | |
| both %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(aes(x = 1, y = pct, fill = fct_rev(ath_pol_f))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ relig_grouped, ncol = 1, strip.position = "left") + | |
| theme_rb() + | |
| theme(legend.position = "bottom") + | |
| scale_y_continuous(labels = scales::percent_format()) + | |
| theme(strip.text.y.left = element_text(angle = 0)) + | |
| guides(fill = guide_legend(reverse = TRUE, nrow = 1)) + | |
| theme( | |
| axis.title.y = element_blank(), | |
| axis.text.y = element_blank(), | |
| axis.ticks.y = element_blank(), | |
| panel.grid.minor.y = element_blank(), | |
| panel.grid.major.y = element_blank(), | |
| plot.title = element_text(size = 16), | |
| strip.text.y.left = element_text(angle = 0, hjust = 1) | |
| ) + | |
| 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 & ath_pol_f == "Strongly Disagree", paste0(lab * 100, '%'), '')), | |
| position = position_stack(vjust = 0.5), | |
| size = 8, family = "font", color = "white") + | |
| scale_fill_manual(values = c( | |
| "Strongly Disagree" = "#4D4D4D", | |
| "Somewhat Disagree" = "#8C8C47", | |
| "Neutral" = "#E2B007", | |
| "Somewhat Agree" = "#7FB77E", | |
| "Strongly Agree" = "#2E8B8B" | |
| )) + | |
| labs( | |
| x = "", y = "", | |
| title = "I am concerned about atheists holding public office.", | |
| caption = "@ryanburge + @jonestony | Data: Making Meaning Survey, 2024" | |
| ) | |
| save("atheists_in_office.png", wd = 9, ht = 5) | |
| mean <- mean %>% | |
| mutate(rel_extreme_f = frcode( | |
| rel_extreme == "Strongly disagree" ~ "Strongly Disagree", | |
| rel_extreme == "Somewhat disagree" ~ "Somewhat Disagree", | |
| rel_extreme == "Neither agree nor disagree" ~ "Neutral", | |
| rel_extreme == "Somewhat agree" ~ "Somewhat Agree", | |
| rel_extreme == "Strongly agree" ~ "Strongly Agree" | |
| )) | |
| gg1 <- mean %>% | |
| ct(rel_extreme_f, wt = wt) %>% | |
| mutate(relig_grouped = "Entire Sample") | |
| gg2 <- mean %>% | |
| mutate(relig_grouped = case_when( | |
| relig %in% c("Hindu", "Muslim", "Orthodox", "Mormon", "Buddhist") ~ "Other Faith", | |
| TRUE ~ relig | |
| )) %>% | |
| group_by(relig_grouped) %>% | |
| ct(rel_extreme_f, wt = wt) | |
| both <- bind_rows(gg1, gg2) | |
| order_levels <- both %>% | |
| filter(rel_extreme_f %in% c("Somewhat Agree", "Strongly Agree")) %>% | |
| group_by(relig_grouped) %>% | |
| summarize(agree_total = sum(pct)) %>% | |
| mutate(order = rank(-agree_total)) %>% | |
| mutate(order = if_else(relig_grouped == "Entire Sample", 0, order + 1)) %>% | |
| arrange(order) %>% | |
| pull(relig_grouped) | |
| both <- both %>% | |
| mutate(relig_grouped = factor(relig_grouped, levels = order_levels)) | |
| both %>% | |
| mutate(lab = round(pct, 2)) %>% | |
| ggplot(aes(x = 1, y = pct, fill = fct_rev(rel_extreme_f))) + | |
| geom_col(color = "black") + | |
| coord_flip() + | |
| facet_wrap(~ relig_grouped, ncol = 1, strip.position = "left") + | |
| theme_rb() + | |
| theme(legend.position = "bottom") + | |
| scale_y_continuous(labels = scales::percent_format()) + | |
| theme(strip.text.y.left = element_text(angle = 0)) + | |
| guides(fill = guide_legend(reverse = TRUE, nrow = 1)) + | |
| theme( | |
| axis.title.y = element_blank(), | |
| axis.text.y = element_blank(), | |
| axis.ticks.y = element_blank(), | |
| panel.grid.minor.y = element_blank(), | |
| panel.grid.major.y = element_blank(), | |
| plot.title = element_text(size = 16), | |
| strip.text.y.left = element_text(angle = 0, hjust = 1) | |
| ) + | |
| 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 & rel_extreme_f == "Strongly Disagree", paste0(lab * 100, '%'), '')), | |
| position = position_stack(vjust = 0.5), | |
| size = 8, family = "font", color = "white") + | |
| scale_fill_manual(values = c( | |
| "Strongly Disagree" = "#4D4D4D", | |
| "Somewhat Disagree" = "#8C8C47", | |
| "Neutral" = "#E2B007", | |
| "Somewhat Agree" = "#7FB77E", | |
| "Strongly Agree" = "#2E8B8B" | |
| )) + | |
| labs( | |
| x = "", y = "", | |
| title = "I am concerned about religious extremists holding public office.", | |
| caption = "@ryanburge + @jonestony | Data: Making Meaning Survey, 2024" | |
| ) | |
| save("rel_extremists.png", wd = 9, ht = 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment