library(socsci)
library(car)
library(janitor)
library(knitr)
library(DT)
library(showtext)
library(Cairo)
source("D://theme.R")
barna <- read_csv("D://bb2.csv") %>% clean_names()

Graph 1

Graph 2

pid_fun <- function(df, ques, name){
  
  ques <- enquo(ques)
  
  df %>% 
    mutate(pid3 = frcode(s20 == 2 ~ "Dem",
                         s20 == 3 ~ "Ind",
                         s20 == 1 ~ "Rep")) %>% 
    group_by(pid3) %>% 
    ct(!! ques, wt = weight) %>% 
    mutate(type = name) %>% 
    na.omit() %>% 
    filter(!! ques == 1) %>% 
    select(pid3, n, pct, type)
  
}

qqq1  <- barna %>% pid_fun(q23_1, "Political Con")  
qqq2  <- barna %>% pid_fun(q23_2, "Religious Con")  
qqq3  <- barna %>% pid_fun(q23_3, "Racist")  
qqq4  <- barna %>% pid_fun(q23_4, "Misogynistic")  
qqq5  <- barna %>% pid_fun(q23_5, "Caring")  
qqq6  <- barna %>% pid_fun(q23_6, "Invasive")  
qqq7  <- barna %>% pid_fun(q23_7, "Friendly")  
qqq8  <- barna %>% pid_fun(q23_8, "Unhappy") 
qqq9  <- barna %>% pid_fun(q23_9, "Encouraging")
qqq10  <- barna %>% pid_fun(q23_10, "Hopeful")  
qqq11  <- barna %>% pid_fun(q23_11, "Uptight")
qqq12  <- barna %>% pid_fun(q23_12, "Good-humored")
qqq13  <- barna %>% pid_fun(q23_13, "Foolish")
qqq14  <- barna %>% pid_fun(q23_14, "Generous")  
qqq15  <- barna %>% pid_fun(q23_15, "Selfish")  
qqq16  <- barna %>% pid_fun(q23_16, "Hurtful")
qqq17  <- barna %>% pid_fun(q23_17, "Homophobic")  
qqq18  <- barna %>% pid_fun(q23_18, "Narrow Minded")  
qqq19  <- barna %>% pid_fun(q23_19, "Puritanical")  
qqq20  <- barna %>% pid_fun(q23_20, "Misunderstood")  


graph <- bind_df("qqq")

graph %>% 
  ggplot(., aes(x = pid3, y = pct, fill = pid3)) +
  geom_col(color = "black") +
  facet_wrap(~ type) +
  pid3_fill() +
  y_pct() +
  theme_gg("Abel") +
  geom_text(aes(y = pct + .035, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 3, family = "font") +
  labs(x = "", y = "", title = "Traits of Evangelicals by Partisanship", caption = "") 

Graph 3