Created
November 23, 2018 19:33
-
-
Save ryanburge/cde6fe4353f4e9a4387afb3d285fd84a to your computer and use it in GitHub Desktop.
Young Evangelicals and the Environment
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
## Environment Issue Positions #### | |
env_fun <- function(df, ques, q2){ | |
ques <- enquo(ques) | |
df %>% | |
filter(race ==1) %>% | |
filter(evangelical ==1) %>% | |
mutate(age = 2016 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
mutate(env = recode(!! ques, "1=1; 2=0; else = NA")) %>% | |
group_by(groups) %>% | |
mean_ci(env) %>% | |
mutate(question = !! q2) | |
} | |
ggg1 <- cces16 %>% env_fun(CC16_333a, "EPA Regulate Carbon Dioxide") | |
ggg2 <- cces16 %>% env_fun(CC16_333b, "Raise Fuel Efficiency Standards") | |
ggg3 <- cces16 %>% env_fun(CC16_333c, "Require Alt. Fuels, Even if Prices Rise") | |
ggg4 <- cces16 %>% env_fun(CC16_333d, "Strengthen Enforce of Clean Air/Water") | |
graph <- bind_df("ggg") | |
graph %>% | |
ggplot(., aes(x = groups, y =mean, fill = groups)) + | |
geom_col(color = "black") + | |
facet_grid(. ~ question) + | |
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9)) + | |
theme_gg("Lato") + | |
scale_y_continuous(labels = percent) + | |
scale_fill_paletteer_d(ghibli, PonyoMedium) + | |
# scale_fill_nord(palette = "red_mountain")+ | |
theme(axis.text.x = element_text(angle = 45, hjust =1)) + | |
labs(x = "Age Group", y = "Percent in Favor", title = "Younger, White Evangelicals are Supportive of Environmental Protection", caption = "Data: CCES 2016") + | |
ggsave("D://env_evan.png", width = 12) | |
## Importance of Environment #### | |
g2 <- cces16 %>% | |
mutate(environment = recode(CC16_301h, "1=5; 2=4; 3=3; 4=2; 5=1; else=99")) %>% | |
filter(race ==1) %>% | |
filter(evangelical ==1) %>% | |
filter(environment != 99) %>% | |
mutate(age = 2016 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
group_by(groups) %>% | |
mean_ci(environment) | |
g2 %>% | |
ggplot(., aes(y=mean, x= groups, color = groups)) + | |
geom_point(position=position_dodge(width=0.5), size =4) + | |
geom_errorbar(aes(ymin = lower, ymax=upper), position=position_dodge(0.5), size = .75, width = .2) + | |
coord_flip() + | |
theme_gg("Lato") + | |
scale_color_paletteer_d(ghibli, PonyoMedium) + | |
labs(title = "How Important is the Environment to You?", x = "Age Group", y = "Level of Importance", caption = "Data: CCES 2016") + | |
scale_y_continuous(limits = c(0.85,5.05), breaks = c(1,2,3,4,5), labels = c("No Importance", "Very Low", "Somewhat Low", "Somewhat High", "Very High")) + | |
ggsave("D://env_imp.png", width = 12) | |
## Mapping Importance on Vote Choice #### | |
fff <- cces16 %>% | |
mutate(environment = recode(CC16_301h, "1=5; 2=4; 3=3; 4=2; 5=1; else=99")) %>% | |
mutate(env2 = recode(environment, "4:5 = 'High Importance '; 1:3 = 'Low Importance '; else= NA")) %>% | |
mutate(vote16 = recode(CC16_410a, "1=1; 2=0; else = NA")) %>% | |
filter(race ==1) %>% | |
filter(evangelical ==1) %>% | |
mutate(age = 2016 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
group_by(groups, env2) %>% | |
mean_ci(vote16) %>% | |
filter(env2 != "NA") | |
fff2 <- cces16 %>% | |
mutate(vote16 = recode(CC16_410a, "1=1; 2=0; else = NA")) %>% | |
filter(race ==1) %>% | |
filter(evangelical ==1) %>% | |
mutate(age = 2016 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
group_by(groups) %>% | |
mean_ci(vote16) %>% | |
mutate(env2 = "Entire Group ") | |
gg <- bind_df("fff") | |
gg$env2 <- factor(gg$env2, levels = c("Low Importance ", "Entire Group ", "High Importance ")) | |
gg %>% | |
ggplot(., aes(x = env2, y = mean, fill = env2)) + | |
geom_col(color = "black") + | |
facet_grid(~ groups) + | |
geom_errorbar(aes(ymin = lower, ymax=upper), position=position_dodge(0.5), size = .75, width = .2) + | |
theme_gg("Lato") + | |
theme(legend.position = "bottom") + | |
scale_y_continuous(labels = percent) + | |
scale_fill_paletteer_d(dutchmasters, milkmaid) + | |
theme(axis.text.x = element_blank()) + | |
theme(axis.ticks.x = element_blank()) + | |
labs(x = "", y = "Share of the Two Party Vote for Trump", title = "The Importance of the Environment and Vote Choice", subtitle = "Among White Evangelicals", caption = "Data: CCES 2016") | |
ggsave("D://env_vote_groups.png", width = 12) | |
### This is doing the 2012 Climate Change Stuff #### | |
library(haven) | |
library(labelled) | |
library(car) | |
cces12 <- read_dta("D://cces/data/cces12.dta") | |
gg2 <- cces12 %>% | |
filter(evangelical ==1) %>% | |
filter(race ==1) %>% | |
mutate(age = 2012 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
group_by(groups) %>% | |
ct(CC321) %>% | |
# mutate(env = recode(CC321, "1 = 'Serious problem-needs immediate action'; | |
# 2 = 'Enough evidence-some action needed'; | |
# 3 = 'Don`t Know Enough-more research necessary'; | |
# 4 = 'Concern is exaggerated-no action necessary'; | |
# 5 = 'Is not occurring-not a real issue'; | |
# else = NA")) %>% | |
na.omit() | |
gg2$env <- factor(gg2$env, levels = c("Serious problem-needs immediate action", "Enough evidence-some action needed", "Don`t Know Enough-more research necessary", "Concern is exaggerated-no action necessary", "Is not occurring-not a real issue")) | |
gg2 %>% | |
ggplot(., aes(x =CC321, y = pct, fill = groups)) + | |
geom_col(color = "black", position = "dodge") + | |
theme_gg("Lato") + | |
theme(legend.position = "bottom") + | |
scale_fill_paletteer_d(ghibli, PonyoMedium) + | |
scale_y_continuous(labels = percent) + | |
geom_text(aes(y = pct + .01, label = paste0(pct*100, '%')), position = position_dodge(width = .9), size = 8, family = "font") + | |
labs(x = "", y = "", title = "View of Climate Change Among White Evangelicals", subtitle = "", caption = "Data: CCES 2012") + | |
scale_x_continuous(breaks = c(1,2,3,4,5), labels = c("Serious problem\nNeeds immediate action", "Enough evidence\nSome action needed", "Don`t know enough\nMore research necessary", "Concern is exaggerated\nNo action necessary", "Is not occurring\nNot a real issue")) + | |
ggsave("D://env12_climate.png", width = 12) | |
gg2 <- cces12 %>% | |
mutate(age = 2012 - birthyr) %>% | |
mutate(groups = recode(age, "18:29 = '18-29'; 30:44 = '30-44'; 45:54 = '45-54'; 55:64 = '55-64'; 65:74 = '65-74'; 75:100 = '75 and Older'")) %>% | |
group_by(groups) %>% | |
ct(CC321) %>% | |
# mutate(env = recode(CC321, "1 = 'Serious problem-needs immediate action'; | |
# 2 = 'Enough evidence-some action needed'; | |
# 3 = 'Don`t Know Enough-more research necessary'; | |
# 4 = 'Concern is exaggerated-no action necessary'; | |
# 5 = 'Is not occurring-not a real issue'; | |
# else = NA")) %>% | |
na.omit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment