Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nones Political
## Mean Estimates ####
aa1 <- cces %>%
filter(none == 1) %>%
filter(year == 2008) %>%
filter(pid7 <= 7) %>%
group_by(state) %>%
mean_ci(pid7, wt = weight, ci = .84) %>%
mutate(year = 2008)
aa2 <- cces %>%
filter(year == 2012) %>%
filter(none == 1) %>%
filter(pid7 <= 7) %>%
group_by(state) %>%
mean_ci(pid7, wt = weight, ci = .84) %>%
mutate(year = 2012)
aa3 <- cces %>%
filter(year == 2018) %>%
filter(none == 1) %>%
filter(pid7 <= 7) %>%
group_by(state) %>%
mean_ci(pid7, wt =weight, ci = .84) %>%
mutate(year = 2018)
gg <- bind_rows(aa1, aa2, aa3)
gg %>%
mutate(year = as.factor(year)) %>%
filter(year != "2012") %>%
ggplot(., aes(y=mean, x = fct_reorder(state, mean), color = year, group = year, fill = year)) +
geom_point(position=position_dodge(width=.5), size =2) +
geom_errorbar(aes(ymin = lower, ymax=upper), position=position_dodge(0.5), width = .15) +
coord_flip() +
ggthemes::scale_color_tableau("Tableau 10") +
ggthemes::scale_fill_tableau("Tableau 10") +
theme_gg("Abel") +
theme(legend.position = "bottom") +
theme(legend.text = element_text(size = 18)) +
theme(plot.title = element_text(size = 22)) +
labs(x = "", y = "Mean Partisan ID", title = "The Shift in Partisanship Among the Nones", caption = "@ryanburge\nData: CCES 2008 - 2018") +
scale_y_continuous(limits = c(1,5.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong\nDemocrat", "Not Strong\nDemocrat", "Lean\nDemocrat", "Independent", "Lean\nRepublican", "Not Strong\nRepublican", "Strong\nRepublican")) +
ggsave("E://state_nones0818.png", type = "cairo-png", height = 10, width = 8)
gg %>%
mutate(year = as.factor(year)) %>%
# filter(year != "2012") %>%
ggplot(., aes(y=mean, x = fct_reorder(state, mean), color = year, group = year, fill = year)) +
geom_point(position=position_dodge(width=.5), size =2) +
geom_errorbar(aes(ymin = lower, ymax=upper), position=position_dodge(0.5), width = .15) +
coord_flip() +
ggthemes::scale_color_tableau("Tableau 10") +
ggthemes::scale_fill_tableau("Tableau 10") +
theme_gg("Abel") +
theme(legend.position = "bottom") +
theme(legend.text = element_text(size = 18)) +
theme(plot.title = element_text(size = 22)) +
labs(x = "", y = "Mean Partisan ID", title = "The Shift in Partisanship Among Nones", caption = "@ryanburge\nData: CCES 2008 - 2018") +
scale_y_continuous(limits = c(1,5.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong\nDemocrat", "Not Strong\nDemocrat", "Lean\nDemocrat", "Independent", "Lean\nRepublican", "Not Strong\nRepublican", "Strong\nRepublican")) +
ggsave("E://state_nones081218.png", type = "cairo-png", height = 10, width = 8)
## Bar Bells ####
bb1 <- cces %>%
filter(year == 2018) %>%
filter(none == 1) %>%
filter(pid7 <= 7) %>%
group_by(state) %>%
mean_ci(pid7, wt =weight)
bb2 <- cces %>%
filter(year == 2018) %>%
filter(pid7 <= 7) %>%
group_by(state) %>%
mean_ci(pid7, wt =weight)
graph <- bind_cols(bb1, bb2) %>%
rename(mean_none = mean) %>%
rename(mean_all = mean1) %>%
mutate(diff = mean_none - mean_all) %>%
mutate(diff2 = diff/6) %>%
mutate(diff2 = diff2*100) %>%
mutate(diff2 = round(diff2, 1)) %>%
mutate(diff2 = diff2*-1) %>%
mutate(diff2 = paste0(diff2, '%'))
graph %>%
ggplot(., aes(x = mean_none, xend = mean_all, y = reorder(state, -diff))) +
geom_dumbbell(colour_x = "#97CAEF", colour_xend = "#FC4445", size = .75, size_x = 2.75, size_xend = 2.75, shape = 21, stroke =2, fill = "white") +
theme_gg("Abel") +
scale_x_continuous(limits = c(2,5.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong\nDemocrat", "Not Strong\nDemocrat", "Lean\nDemocrat", "Independent", "Lean\nRepublican", "Not Strong\nRepublican", "Strong\nRepublican")) +
theme(axis.text.y = element_text(size = 14)) +
theme(axis.text.x = element_text(size = 18)) +
theme(plot.title = element_text(size = 22)) +
geom_text(data = filter(graph, state == "South Dakota"), aes(x= mean_none, y = state, label = "Nones"), hjust = 1.35, family = "font", size = 4) +
geom_text(data = filter(graph, state == "South Dakota"), aes(x= mean_all, y = state, label = "Overall"), hjust = -.35, family = "font", size = 4) +
geom_text(data = filter(graph, state == "Ohio"), aes(x= mean_none, y = state, label = "Nones"), hjust = 1.35, family = "font", size = 4) +
geom_text(data = filter(graph, state == "Ohio"), aes(x= mean_all, y = state, label = "Overall"), hjust = -.35, family = "font", size = 4) +
geom_rect(data=graph, aes(xmin=5.32, xmax=5.50, ymin=-Inf, ymax=Inf), fill="gray") +
geom_text(data=graph, aes(label=diff2, y=state, x=5.41), fontface="bold", size=4, family="font") +
labs(x = "", y = "", title = "In Which States are the Nones the Most Politically Distinct?", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://nones_pid_barbells.png", type = "cairo-png", height = 10, width = 10)
### PID GSS LONG ####
graph <- gss %>%
filter(nofaith == 1) %>%
filter(partyid <= 6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(group = "Nones")
graph1 <- gss %>%
filter(partyid <= 6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(group = "Entire Sample")
tt <- bind_rows(graph, graph1)
tt %>%
ggplot(., aes(x = year, y = mean, group = group, color = group)) +
geom_point() +
geom_line() +
geom_ribbon(aes(ymin = lower, ymax = upper), alpha = .2) +
scale_color_manual(values = c("#FC4445", "#97CAEF")) +
scale_fill_manual(values = c("#FC4445", "#97CAEF")) +
scale_y_continuous(limits = c(1, 4), breaks = c(0,1,2,3,4,5,6), labels = c("Strong\nDemocrat", "Not Strong\nDemocrat", "Independent\nNear Democrat", "Independent", "Independent\nNear Republican", "Not Strong\nRepubblican", "Strong\nRep")) +
theme_gg("Abel") +
annotate("text", x=2009, y = 3.0 , label = "Entire Sample", size = 6, family = "font") +
annotate("text", x=2010, y = 2.1 , label = "Nones", size = 6, family = "font") +
labs(x = "", y = "", title = "Mean Partisanship of the Nones", caption = "@ryanburge\nData: GSS 1972-2018") +
ggsave("E://nones_gss_lines.png", type = "cairo-png")
graph <- gss %>%
filter(nofaith == 1) %>%
filter(partyid <= 6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(group = "Nones")
graph1 <- gss %>%
filter(evangelical == 1) %>%
filter(partyid <= 6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(group = "Evangelical")
graph2 <- gss %>%
filter(mainline == 1) %>%
filter(partyid <= 6) %>%
group_by(year) %>%
mean_ci(partyid, wt = wtssall) %>%
mutate(group = "Mainline")
tt <- bind_rows(graph, graph1, graph2)
tt %>%
ggplot(., aes(x = year, y = mean, group = group, color = group)) +
geom_point(size=4, color="white") +
geom_point(size=3, shape=1, alpha=.5) +
geom_point(size=2, shape=19) +
geom_line() +
geom_ribbon(aes(ymin = lower, ymax = upper), alpha = .2) +
ggthemes::scale_color_tableau() +
ggthemes::scale_fill_tableau() +
scale_y_continuous(limits = c(1, 4), breaks = c(0,1,2,3,4,5,6), labels = c("Strong\nDemocrat", "Not Strong\nDemocrat", "Independent\nNear Democrat", "Independent", "Independent\nNear Republican", "Not Strong\nRepubblican", "Strong\nRep")) +
theme_gg("Abel") +
annotate("text", x=2011, y = 3.0 , label = "Mainline", size = 6, family = "font") +
annotate("text", x=2010, y = 2.1 , label = "Nones", size = 6, family = "font") +
annotate("text", x=2013, y = 3.7 , label = "Evangelical", size = 6, family = "font") +
labs(x = "", y = "", title = "Mean Partisanship of Religious Groups", caption = "@ryanburge\nData: GSS 1972-2018") +
ggsave("E://nones_gss_lines_3groups.png", type = "cairo-png")
## 2008 Map ####
cces08 <- read_dta("D://cces/data/cces08.dta")
source("D://reltrad/CCES/reltrad08.R")
map <- cces08 %>%
filter(none == 1) %>%
filter(V206 <= 56) %>%
mutate(state = to_factor(V206)) %>%
mutate(dem = car::recode(CC327, "2=1; 1=0; else = NA")) %>%
group_by(state) %>%
mean_ci(dem, wt = V201) %>%
mutate(region = tolower(state))
center <- read_csv("D://centers.csv")
library(maps)
us_states <- map_data("state") %>% as_tibble()
mapp <- left_join(us_states, map) %>% as_tibble()
mapp %>%
ggplot(., mapping = aes(x = long, y = lat, group = group, fill = mean)) +
geom_polygon(color = "gray90", size = 0.1) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradient2(high = "dodgerblue", mid = "azure3", low = "firebrick3", midpoint = .7, labels = percent) +
theme_gg("Abel") +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
panel.spacing = unit(0, "lines"),
plot.background = element_blank(),
legend.justification = c(0, 0),
legend.position = "right",
plot.title = element_text(size = 14)) +
labs(title = "Two Party Vote in 2008 Among the Nones", subtitle = "", caption = "@ryanburge\nData: CCES 2008") +
ggsave("E://nones_votes08.png", type = "cairo-png")
## 2012 Map ####
cces12 <- read_dta("D://cces/data/cces12.dta")
source("D://reltrad/CCES/reltrad12.R")
map <- cces12 %>%
filter(none == 1) %>%
filter(inputstate <= 56) %>%
mutate(state = to_factor(inputstate)) %>%
mutate(dem = car::recode(CC410a, "1=1; 2=0; else = NA")) %>%
group_by(state) %>%
mean_ci(dem) %>%
mutate(region = tolower(state))
library(maps)
us_states <- map_data("state") %>% as_tibble()
mapp <- left_join(us_states, map) %>% as_tibble()
mapp %>%
ggplot(., mapping = aes(x = long, y = lat, group = group, fill = mean)) +
geom_polygon(color = "gray90", size = 0.1) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradient2(high = "dodgerblue", mid = "azure3", low = "firebrick3", midpoint = .7, labels = percent) +
theme_gg("Abel") +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
panel.spacing = unit(0, "lines"),
plot.background = element_blank(),
legend.justification = c(0, 0),
legend.position = "right",
plot.title = element_text(size = 14)) +
labs(title = "Two Party Vote in 2012 Among the Nones", subtitle = "", caption = "@ryanburge\nData: CCES 2012") +
ggsave("E://nones_votes12.png", type = "cairo-png")
## 2016 Map ####
cces16 <- read_dta("D://cces/data/cces16.dta")
source("D://reltrad/CCES/reltrad16.R")
map <- cces16 %>%
filter(none == 1) %>%
filter(inputstate <= 56) %>%
mutate(state = to_factor(inputstate)) %>%
mutate(dem = car::recode(CC16_410a, "2=1; 1=0; else = NA")) %>%
group_by(state) %>%
mean_ci(dem) %>%
mutate(region = tolower(state))
library(maps)
us_states <- map_data("state") %>% as_tibble()
mapp <- left_join(us_states, map) %>% as_tibble()
mapp %>%
ggplot(., mapping = aes(x = long, y = lat, group = group, fill = mean)) +
geom_polygon(color = "gray90", size = 0.1) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradient2(high = "dodgerblue", mid = "azure3", low = "firebrick3", midpoint = .7, labels = percent) +
theme_gg("Abel") +
theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid = element_blank(),
panel.spacing = unit(0, "lines"),
plot.background = element_blank(),
legend.justification = c(0, 0),
legend.position = "right",
plot.title = element_text(size = 14)) +
labs(title = "Two Party Vote in 2016 Among the Nones", subtitle = "", caption = "@ryanburge\nData: CCES 2016") +
ggsave("E://nones_votes16.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.