Making Dumbbells of PID Moves
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
library(haven) | |
library(labelled) | |
cces08 <- read_dta("D://cces/data/cces08.dta") | |
cces10 <- read_dta("D://cces/data/cces10.dta") | |
cces12 <- read_dta("D://cces/data/cces12.dta") | |
cces14 <- read_dta("D://cces/data/cces14.dta") | |
cces16 <- read_dta("D://cces/data/cces16.dta") | |
cces18 <- read_dta("D://cces18.dta") | |
### Calculating 2008 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(CC307a)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V201) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces08, V223, "Methodist") | |
aa1 <- fun(cces08, V222, "Baptist") | |
aa2 <- fun(cces08, V224, "Non-Denom") | |
aa3 <- fun(cces08, V225, "Lutheran") | |
aa4 <- fun(cces08, V226, "Presbyterian") | |
aa5 <- fun(cces08, V227, "Pentecostal") | |
aa6 <- fun(cces08, V228, "Episcopal") | |
aa7 <- fun(cces08, V229, "Congregational") | |
aa8 <- fun(cces08, V230, "Holiness") | |
aa9 <- fun(cces08, V231, "Reformed") | |
aa10 <- cces08 %>% | |
group_by(V219) %>% | |
mutate(partyid = as.numeric(CC307a)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V201) %>% | |
mutate(relig = to_factor(V219)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc08 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,08))) %>% | |
filter(relig8 != "NA") | |
### Calculating 2010 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(V212d)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V101) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces10, V223, "Methodist") | |
aa1 <- fun(cces10, V222, "Baptist") | |
aa2 <- fun(cces10, V224, "Non-Denom") | |
aa3 <- fun(cces10, V225, "Lutheran") | |
aa4 <- fun(cces10, V226, "Presbyterian") | |
aa5 <- fun(cces10, V227, "Pentecostal") | |
aa6 <- fun(cces10, V228, "Episcopal") | |
aa7 <- fun(cces10, V229, "Congregational") | |
aa8 <- fun(cces10, V230, "Holiness") | |
aa9 <- fun(cces10, V231, "Reformed") | |
aa10 <- cces10 %>% | |
group_by(V219) %>% | |
mutate(partyid = as.numeric(V212d)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V101) %>% | |
mutate(relig = to_factor(V219)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc10 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,10))) %>% | |
filter(relig10 != "NA") | |
## Calculating 2012 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight_vv) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces12, religpew_methodist, "Methodist") | |
aa1 <- fun(cces12, religpew_baptist, "Baptist") | |
aa2 <- fun(cces12, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces12, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces12, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces12, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces12, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces12, religpew_congreg, "Congregational") | |
aa8 <- fun(cces12, religpew_holiness, "Holiness") | |
aa9 <- fun(cces12, religpew_reformed, "Reformed") | |
aa10 <- cces12 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight_vv) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc12 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,12))) | |
## Calculating 2014 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces14, religpew_methodist, "Methodist") | |
aa1 <- fun(cces14, religpew_baptist, "Baptist") | |
aa2 <- fun(cces14, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces14, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces14, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces14, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces14, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces14, religpew_congreg, "Congregational") | |
aa8 <- fun(cces14, religpew_holiness, "Holiness") | |
aa9 <- fun(cces14, religpew_reformed, "Reformed") | |
aa10 <- cces14 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc14 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,14))) %>% | |
filter(relig14 != "NA") | |
## Calculating 2016 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight_vv_post) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces16, religpew_methodist, "Methodist") | |
aa1 <- fun(cces16, religpew_baptist, "Baptist") | |
aa2 <- fun(cces16, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces16, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces16, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces16, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces16, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces16, religpew_congreg, "Congregational") | |
aa8 <- fun(cces16, religpew_holiness, "Holiness") | |
aa9 <- fun(cces16, religpew_reformed, "Reformed") | |
aa10 <- cces16 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc16 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,16))) %>% | |
filter(relig16 != "NA") | |
## Calculating 2018 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces18, religpew_methodist, "Methodist") | |
aa1 <- fun(cces18, religpew_baptist, "Baptist") | |
aa2 <- fun(cces18, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces18, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces18, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces18, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces18, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces18, religpew_congreg, "Congregational") | |
aa8 <- fun(cces18, religpew_holiness, "Holiness") | |
aa9 <- fun(cces18, religpew_reformed, "Reformed") | |
aa10 <- cces18 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc18 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) %>% | |
rename_all(funs(paste0(.,18))) %>% | |
filter(relig18 != "NA") | |
first <- left_join(cc08, cc10, by = c("relig8" = "relig10")) | |
second <- left_join(cc12, cc14, by = c("relig12" = "relig14")) | |
third <- left_join(cc16, cc18, by = c("relig16" = "relig18")) | |
fourth <- left_join(first, second, by = c("relig8" = "relig12")) | |
graph <- left_join(fourth, third, by = c("relig8" = "relig16")) | |
graph <- graph %>% | |
filter(n8 > 100 & n10 > 100 & n12 > 100 & n14 >100 & n16 >100 & n18 > 100) %>% | |
mutate(diff1816 = mean18 - mean16) %>% | |
mutate(diff1812 = mean18 - mean12) %>% | |
mutate(diff1808 = mean18 - mean8) %>% | |
mutate(diff1816 = round(diff1816, 2)) %>% | |
mutate(diff1812 = round(diff1812, 2)) %>% | |
mutate(diff1808 = round(diff1808, 2)) | |
graph %>% | |
ggplot(., aes(x = mean12, xend = mean18, y = reorder(relig, mean18))) + | |
geom_dumbbell(colour_x = "#EF5445", colour_xend = "#FAD744", size = .75, size_x = 2.75, size_xend = 2.75, shape = 21, stroke =2, fill = "black") + | |
theme_gg("Abel") + | |
theme(axis.text.y = element_text(size = 14)) + | |
labs(x= "Mean Party ID", y = "Religious Tradition", title = "Change in Party Identification from 2012 to 2018", caption = "Data: CCES 2012 and 2018", subtitle = "") + | |
scale_x_continuous(limits = c(1,6.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Very\nStrong Democrat", "Lean Democrat", "Independent", "Lean Republican", "", "Strong Republican")) + | |
geom_vline(xintercept = 3.73, color = "black", linetype = "dashed") + | |
annotate("text", x=3.851, y = 31, label = "Avg.", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 30, label = "2012", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 29, label = "And", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 28, label = "2018", size = 4, family = "font") + | |
geom_text(data = filter(graph, relig == "Independent Baptist"), aes(x= mean12, y = relig, label = "2012"), hjust = 1.35, family = "font", size = 4) + | |
geom_text(data = filter(graph, relig == "Independent Baptist"), aes(x= mean18, y = relig, label = "2018"), hjust = -.35, family = "font", size = 4) + | |
geom_rect(data=graph, aes(xmin=5.9, xmax=6.2, ymin=-Inf, ymax=Inf), fill="gray") + | |
geom_text(data=graph, aes(label=diff1812, y=relig, x=6.05), fontface="bold", size=4, family="font") + | |
geom_text(data=filter(graph, relig=="Assemblies of God"), aes(x=1.05, y=relig, label=""), size=10, fontface="bold", family="font", vjust = -.65) + | |
ggsave("D://cces/images/pid_moves1218.png", height = 10, width = 12) | |
graph <- left_join(cc08, cc18, by = c("relig8" = "relig18")) %>% | |
filter(n8 > 100 & n18 > 100) %>% | |
mutate(diff1808 = mean18 - mean8) %>% | |
mutate(diff1808 = round(diff1808, 2)) | |
graph %>% | |
ggplot(., aes(x = mean8, xend = mean18, y = reorder(relig8, mean18))) + | |
geom_dumbbell(colour_x = "#EF5445", colour_xend = "#FAD744", size = .75, size_x = 2.75, size_xend = 2.75, shape = 21, stroke =2, fill = "black") + | |
theme_gg("Abel") + | |
theme(axis.text.y = element_text(size = 14)) + | |
labs(x= "Mean Party ID", y = "Religious Tradition", title = "Change in Party Identification from 2008 to 2018", caption = "Data: CCES 2008 and 2018", subtitle = "") + | |
scale_x_continuous(limits = c(1,6.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Very\nStrong Democrat", "Lean Democrat", "Independent", "Lean Republican", "", "Strong Republican")) + | |
geom_vline(xintercept = 3.73, color = "black", linetype = "dashed") + | |
annotate("text", x=3.851, y = 31, label = "Avg.", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 30, label = "2008", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 29, label = "And", size = 4, family = "font") + | |
annotate("text", x=3.851, y = 28, label = "2018", size = 4, family = "font") + | |
geom_text(data = filter(graph, relig8 == "Independent Baptist"), aes(x= mean8, y = relig8, label = "2008"), hjust = 1.35, family = "font", size = 4) + | |
geom_text(data = filter(graph, relig8 == "Independent Baptist"), aes(x= mean18, y = relig8, label = "2018"), hjust = -.35, family = "font", size = 4) + | |
geom_text(data = filter(graph, relig8 == "Atheist"), aes(x= mean8, y = relig8, label = "2018"), hjust = 2.65, family = "font", size = 4) + | |
geom_text(data = filter(graph, relig8 == "Atheist"), aes(x= mean18, y = relig8, label = "2008"), hjust = -1.65, family = "font", size = 4) + | |
geom_rect(data=graph, aes(xmin=5.9, xmax=6.2, ymin=-Inf, ymax=Inf), fill="gray") + | |
geom_text(data=graph, aes(label=diff1808, y=relig8, x=6.05), fontface="bold", size=4, family="font") + | |
geom_text(data=filter(graph, relig8=="Assemblies of God"), aes(x=1.05, y=relig8, label=""), size=10, fontface="bold", family="font", vjust = -.65) + | |
ggsave("D://cces/images/pid_moves0818.png", height = 10, width = 12) | |
## This is making the longitudinal stuff #### | |
### Calculating 2008 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(CC307a)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V201) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces08, V223, "Methodist") | |
aa1 <- fun(cces08, V222, "Baptist") | |
aa2 <- fun(cces08, V224, "Non-Denom") | |
aa3 <- fun(cces08, V225, "Lutheran") | |
aa4 <- fun(cces08, V226, "Presbyterian") | |
aa5 <- fun(cces08, V227, "Pentecostal") | |
aa6 <- fun(cces08, V228, "Episcopal") | |
aa7 <- fun(cces08, V229, "Congregational") | |
aa8 <- fun(cces08, V230, "Holiness") | |
aa9 <- fun(cces08, V231, "Reformed") | |
aa10 <- cces08 %>% | |
group_by(V219) %>% | |
mutate(partyid = as.numeric(CC307a)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V201) %>% | |
mutate(relig = to_factor(V219)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc08 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
### Calculating 2010 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(V212d)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V101) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces10, V223, "Methodist") | |
aa1 <- fun(cces10, V222, "Baptist") | |
aa2 <- fun(cces10, V224, "Non-Denom") | |
aa3 <- fun(cces10, V225, "Lutheran") | |
aa4 <- fun(cces10, V226, "Presbyterian") | |
aa5 <- fun(cces10, V227, "Pentecostal") | |
aa6 <- fun(cces10, V228, "Episcopal") | |
aa7 <- fun(cces10, V229, "Congregational") | |
aa8 <- fun(cces10, V230, "Holiness") | |
aa9 <- fun(cces10, V231, "Reformed") | |
aa10 <- cces10 %>% | |
group_by(V219) %>% | |
mutate(partyid = as.numeric(V212d)) %>% | |
filter(partyid <=7) %>% | |
mean_ci(partyid, wt = V101) %>% | |
mutate(relig = to_factor(V219)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc10 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
## Calculating 2012 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight_vv) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces12, religpew_methodist, "Methodist") | |
aa1 <- fun(cces12, religpew_baptist, "Baptist") | |
aa2 <- fun(cces12, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces12, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces12, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces12, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces12, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces12, religpew_congreg, "Congregational") | |
aa8 <- fun(cces12, religpew_holiness, "Holiness") | |
aa9 <- fun(cces12, religpew_reformed, "Reformed") | |
aa10 <- cces12 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight_vv) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc12 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
## Calculating 2014 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces14, religpew_methodist, "Methodist") | |
aa1 <- fun(cces14, religpew_baptist, "Baptist") | |
aa2 <- fun(cces14, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces14, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces14, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces14, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces14, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces14, religpew_congreg, "Congregational") | |
aa8 <- fun(cces14, religpew_holiness, "Holiness") | |
aa9 <- fun(cces14, religpew_reformed, "Reformed") | |
aa10 <- cces14 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = weight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc14 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
## Calculating 2016 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight_vv_post) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces16, religpew_methodist, "Methodist") | |
aa1 <- fun(cces16, religpew_baptist, "Baptist") | |
aa2 <- fun(cces16, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces16, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces16, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces16, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces16, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces16, religpew_congreg, "Congregational") | |
aa8 <- fun(cces16, religpew_holiness, "Holiness") | |
aa9 <- fun(cces16, religpew_reformed, "Reformed") | |
aa10 <- cces16 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc16 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
## Calculating 2018 #### | |
fun <- function(df, relig, fam){ | |
relig <- enquo(relig) | |
fam <- enquo(fam) | |
df %>% | |
group_by(!! relig) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(!! relig)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = !! fam) | |
} | |
aa <- fun(cces18, religpew_methodist, "Methodist") | |
aa1 <- fun(cces18, religpew_baptist, "Baptist") | |
aa2 <- fun(cces18, religpew_nondenom, "Non-Denom") | |
aa3 <- fun(cces18, religpew_lutheran, "Lutheran") | |
aa4 <- fun(cces18, religpew_presby, "Presbyterian") | |
aa5 <- fun(cces18, religpew_pentecost, "Pentecostal") | |
aa6 <- fun(cces18, religpew_episcop, "Episcopal") | |
aa7 <- fun(cces18, religpew_congreg, "Congregational") | |
aa8 <- fun(cces18, religpew_holiness, "Holiness") | |
aa9 <- fun(cces18, religpew_reformed, "Reformed") | |
aa10 <- cces18 %>% | |
group_by(religpew) %>% | |
mutate(partyid = as.numeric(pid7)) %>% | |
filter(pid7 <=7) %>% | |
mean_ci(pid7, wt = commonweight) %>% | |
mutate(relig = to_factor(religpew)) %>% | |
filter(relig != "Skipped") %>% | |
mutate(family = "fam") | |
cc18 <- bind_df("aa") %>% | |
select(relig, family, mean, sd, n, se, lower, upper) | |
cc08 <- cc08 %>% mutate(year = 2008) | |
cc10 <- cc10 %>% mutate(year = 2010) | |
cc12 <- cc12 %>% mutate(year = 2012) | |
cc14 <- cc14 %>% mutate(year = 2014) | |
cc16 <- cc16 %>% mutate(year = 2016) | |
cc18 <- cc18 %>% mutate(year = 2018) | |
all <- bind_rows(cc08, cc10, cc12, cc14, cc16, cc18) %>% | |
filter(relig != "NA") | |
all %>% | |
filter(relig == "United Methodist Church" | relig == "Episcopal Church in the USA" | relig == "American Baptist Churches in USA" | relig == "Presbyterian Church USA") %>% | |
ggplot(., aes(x = year, y=mean, color = relig)) + | |
geom_point() + | |
geom_line() + | |
theme_gg("Abel") + | |
scale_color_paletteer_d(ggsci, default_jco) + | |
scale_fill_paletteer_d(ggsci, default_jco) + | |
scale_x_continuous(breaks = c(2008, 2010, 2012, 2014, 2016, 2018)) + | |
theme(legend.position = "none") + | |
theme(plot.title = element_text(size = 14)) + | |
geom_ribbon(aes(ymin=lower, ymax=upper, color = relig, fill = relig), alpha = .4, show.legend = FALSE) + | |
annotate("text", x=2013, y = 3.25, label = "American Baptist", size = 4, family = "font") + | |
annotate("text", x=2014, y = 3.75, label = "Episcopal", size = 4, family = "font") + | |
annotate("text", x=2014, y = 4.15, label = "PCUSA", size = 4, family = "font") + | |
annotate("text", x=2015, y = 4.45, label = "United Methodist", size = 4, family = "font") + | |
scale_y_continuous(limits = c(2,5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Very\nStrong Democrat", "Lean Democrat", "Independent", "Lean Republican", "", "Strong Republican")) + | |
labs(x = "Year",y = "Average Party Identification", title = "Mainline Churches and Partisanship over the Last Decade", caption = "Data: CCES 2008-2018") + | |
ggsave("D://cces/images/ml_pid_years.png", type = "cairo-png") | |
all %>% | |
filter(relig == "Southern Baptist Convention" | relig == "Nondenominational evangelical" | relig == "Lutheran Church, Missouri Synod" | relig == "Assemblies of God") %>% | |
ggplot(., aes(x = year, y=mean, color = relig)) + | |
geom_point() + | |
geom_line() + | |
theme_gg("Abel") + | |
scale_color_paletteer_d(ggsci, default_jco) + | |
scale_fill_paletteer_d(ggsci, default_jco) + | |
scale_x_continuous(breaks = c(2008, 2010, 2012, 2014, 2016, 2018)) + | |
theme(legend.position = "none") + | |
theme(plot.title = element_text(size = 14)) + | |
geom_ribbon(aes(ymin=lower, ymax=upper, color = relig, fill = relig), alpha = .4, show.legend = FALSE) + | |
annotate("text", x=2013, y = 4.44, label = "SBC", size = 4, family = "font") + | |
annotate("text", x=2010, y = 4.8, label = "Lutheran - MO Synod", size = 4, family = "font") + | |
annotate("text", x=2010.5, y = 5.35, label = "Nondenominational evangelical", size = 4, family = "font") + | |
annotate("text", x=2017, y = 5.35, label = "AoG", size = 4, family = "font") + | |
scale_y_continuous(limits = c(3.25,6), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Very\nStrong Democrat", "Lean Democrat", "Independent", "Lean Republican", "Not Very\nStrong Republican", "Strong Republican")) + | |
labs(x = "Year",y = "Average Party Identification", title = "Evangelical Churches and Partisanship over the Last Decade", caption = "Data: CCES 2008-2018") + | |
ggsave("D://cces/images/evan_pid_years.png", type = "cairo-png") | |
all %>% | |
filter(relig == "Atheist" | relig == "Agnostic" | relig == "Nothing in particular") %>% | |
ggplot(., aes(x = year, y=mean, color = relig)) + | |
geom_point() + | |
geom_line() + | |
theme_gg("Abel") + | |
scale_color_paletteer_d(ggsci, default_jco) + | |
scale_fill_paletteer_d(ggsci, default_jco) + | |
scale_x_continuous(breaks = c(2008, 2010, 2012, 2014, 2016, 2018)) + | |
theme(legend.position = "none") + | |
theme(plot.title = element_text(size = 14)) + | |
geom_ribbon(aes(ymin=lower, ymax=upper, color = relig, fill = relig), alpha = .4, show.legend = FALSE) + | |
annotate("text", x=2015, y = 3.14, label = "Agnostic", size = 4, family = "font") + | |
annotate("text", x=2014, y = 2.83, label = "Atheist", size = 4, family = "font") + | |
annotate("text", x=2012, y = 3.4, label = "Nothing in particular", size = 4, family = "font") + | |
scale_y_continuous(limits = c(1.25,4.5), breaks = c(1,2,3,4,5,6,7), labels = c("Strong Democrat", "Not Very\nStrong Democrat", "Lean Democrat", "Independent", "Lean Republican", "Not Very\nStrong Republican", "Strong Republican")) + | |
labs(x = "Year",y = "Average Party Identification", title = "Nones and Partisanship over the Last Decade", caption = "Data: CCES 2008-2018") + | |
ggsave("D://cces/images/nones_pid_years.png", type = "cairo-png") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment