pc <- data.frame(stringsAsFactors=FALSE,
type = c("Unweighted", "practicing Christians", "Christians, not practicing",
"all non-Christians"),
NA2000 = c("757", "45%", "35%", "20%"),
NA2001 = c("818", "43%", "34%", "22%"),
NA2002 = c("3626", "42%", "30%", "28%"),
NA2003 = c("817", "47%", "32%", "21%"),
NA2004 = c("3243", "46%", "33%", "21%"),
NA2005 = c("4015", "45%", "28%", "28%"),
NA2006 = c("4014", "47%", "32%", "21%"),
NA2007 = c("4011", "46%", "33%", "22%"),
NA2008 = c("6224", "48%", "31%", "21%"),
NA2009 = c("2002", "50%", "30%", "20%"),
NA2010 = c("4028", "47%", "33%", "20%"),
NA2011 = c("2628", "41%", "35%", "24%"),
NA2012 = c("5093", "31%", "33%", "36%"),
NA2013 = c("6578", "31%", "44%", "25%"),
NA2014 = c("6151", "27%", "45%", "28%"),
NA2015 = c("7284", "30%", "43%", "27%"),
NA2016 = c("7441", "28%", "42%", "29%"),
NA2017 = c("5083", "26%", "41%", "33%"),
NA2018 = c("4114", "25%", "45%", "31%"),
NA2019 = c("5062", "25%", "45%", "30%")
)
pc <- melt(pc, id.vars = c("type")) %>%
as_tibble()
pc <- pc %>%
mutate(year = gsub("NA", "", .$variable)) %>%
mutate(year = as.numeric(year)) %>%
mutate(value = gsub("%", "", .$value)) %>%
mutate(pct = as.numeric(value)/100) %>%
select(type, year, pct) %>%
filter(type != "Unweighted")
pc %>%
ggplot(., aes(x = year, y = pct, fill = type)) +
geom_area(alpha = .6, color = "black") +
y_pct() +
theme_gg("Abel", legend = TRUE) +
scale_fill_tableau() +
labs(x = "", y = "", title = "Practicing Christians Over Time") att <- data.frame(stringsAsFactors=FALSE,
age = c("Millennials", "Gen X", "Boomers", "Elders"),
"2003" = c("39%", "34%", "45%", "51%"),
"2019" = c("24%", "31%", "35%", "41%")
) %>%
as_tibble()
left <- att %>%
select(age, year = X2003) %>%
mutate(pct = gsub("%", "", .$year)) %>%
mutate(pct = as.numeric(pct)/100)
right <- att %>%
select(age, year = X2019) %>%
mutate(pct = gsub("%", "", .$year)) %>%
mutate(pct = as.numeric(pct)/100)
left_label <- paste(left$age, left$year, sep = ": ")
right_label <- paste(right$age, right$year, sep = ": ")
sl <- bind_cols(left, right)
ggplot(sl) +
geom_segment(aes(x=1, xend =2, y = pct, yend = pct1, col= age), size = .75, show.legend = FALSE, linetype = "twodash") +
scale_y_continuous(labels = percent, limits = c(.23, .53)) +
geom_vline(xintercept=1, linetype="dashed", size=.1) +
geom_vline(xintercept=2, linetype="dashed", size=.1) +
xlim(.25, 2.75) +
scale_color_tableau() +
geom_text(label=left_label, y=sl$pct, x=rep(1, NROW(sl)), hjust=1.05, size=4.5, family = "font") +
geom_text(label=right_label, y=sl$pct1, x=rep(2, NROW(sl)), hjust=-0.05, size=4.5, family = "font") +
geom_text(label="2003", x=1, y=.525, hjust=1.1, size=5, family = "font") +
geom_text(label="2019", x=2, y=.525, hjust=-.1, size=5, family = "font") +
theme_gg("Abel") +
theme(panel.background = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.text.x = element_blank(),
panel.border = element_blank()) +
labs(x = "", y = "", title = "Weekly Attendance by Generation", caption = "") These don’t sum up to 100% in 2011 or 2019 because of rounding issues.
bible <- data.frame(stringsAsFactors=FALSE,
freq = c("Never", "Less than once a year", "Once or twice a year",
"Three or four times a year", "Once a month", "Once a week",
"Several times/4+ times a week", "Every day", "Not sure"),
NA2011 = c("25", "13", "11", "8", "8", "8", "15", "11", "3"),
NA2012 = c("26", "10", "10", "9", "8", "7", "13", "13", "5"),
NA2013 = c("26", "12", "10", "9", "7", "8", "13", "13", "1"),
NA2014 = c("26", "9", "11", "8", "8", "9", "13", "15", "2"),
NA2015 = c("28", "10", "10", "6", "9", "8", "14", "14", "1"),
NA2016 = c("27", "14", "9", "8", "7", "8", "14", "13", "2"),
NA2017 = c("32", "10", "8", "6", "7", "7", "14", "16", "1"),
NA2018 = c("32", "12", "8", "8", "6", "8", "13", "14", "1"),
NA2019 = c("35", "10", "7", "6", "7", "8", "14", "14", "1")
) %>%
as_tibble()
bible <- bible %>%
select(freq, NA2011, NA2015, NA2019)
bible <- melt(bible, id.vars = "freq")
bible <- bible %>%
mutate(year = gsub("NA", "", .$variable)) %>%
mutate(year = as.numeric(year)) %>%
mutate(pct = as.numeric(value)/100) %>%
select(freq, year, pct) %>%
as_tibble()
bible$freq <- factor(bible$freq, levels = c("Not sure", "Never", "Less than once a year", "Once or twice a year", "Three or four times a year", "Once a month", "Once a week", "Several times/4+ times a week", "Every day"))
bible %>%
ggplot(., aes(x=1, y = pct, fill = fct_rev(freq))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ year, ncol =1) +
theme_gg("Abel") +
theme(legend.position = "bottom") +
scale_fill_d3() +
scale_y_continuous(labels = percent) +
guides(fill = guide_legend(reverse=T, nrow =2)) +
theme(axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
theme(legend.text = element_text(size = 6)) +
geom_text(aes(label = ifelse(pct >.05, paste0(pct*100, '%'), '')), position = position_stack(vjust = 0.5), size = 4, family = "font", color = "black") +
theme(panel.grid.major.y = element_blank()) +
theme(panel.grid.minor.y = element_blank()) +
theme(plot.title = element_text(size = 16)) +
labs(x = "", y = "", title = "Bible Reading", caption = "") pid <- data.frame(stringsAsFactors=FALSE,
year = c(2003, 2006, 2009, 2012, 2015, 2018, 2019),
NADemocrat = c("85%", "86%", "85%", "83%", "76%", "70%", "70%"),
NARepublican = c("88%", "88%", "89%", "88%", "79%", "83%", "77%"),
NAIndependent = c("78%", "76%", "78%", "75%", "70%", "63%", "63%")
)
pid <- melt(pid, id.vars = "year")
pid <- pid %>%
mutate(pid = gsub("NA", "", .$variable)) %>%
mutate(year = as.numeric(year)) %>%
mutate(pct = gsub("%", "", .$value)) %>%
mutate(pct = as.numeric(pct)/100) %>%
select(year, pid, pct) %>%
as_tibble()
pid$pid <- factor(pid$pid, levels = c("Democrat", "Independent", "Republican"))
pid %>%
mutate(year = as.factor(year)) %>%
ggplot(., aes(x = year, y = pct, fill = pid)) +
geom_col(color = "black", position = "dodge") +
pid3_fill() +
lab_bar(type = pct, pos = .02, sz = 3) +
theme_gg("Abel", legend = TRUE) +
y_pct() +
labs(x = "", y = "", title = "Prayer by Party ID")