Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created November 23, 2020 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburge/4fef6e48b3f4dad55f9c754c2a3587ca to your computer and use it in GitHub Desktop.
Save ryanburge/4fef6e48b3f4dad55f9c754c2a3587ca to your computer and use it in GitHub Desktop.
Episcopalian Post
gg <- cces18 %>%
mutate(trad = frcode(religpew == 2 ~ "Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
religpew == 12 ~ "Something Else",
religpew_baptist == 1 ~ "Southern Baptist",
religpew_baptist == 2 ~ "ABCUSA",
religpew_baptist == 3 ~ "Natl. Baptist Convention",
religpew_baptist == 4 ~ "Progressive Baptist Convention",
religpew_baptist == 5 ~ "Independent Baptist",
religpew_baptist == 6 ~ "Baptist General Conference",
religpew_baptist == 7 ~ "Baptist Miss. Association",
religpew_baptist == 8 ~ "Conservative Bapt. Association",
religpew_baptist == 9 ~ "Free Will Baptist",
religpew_baptist == 10 ~ "Gen. Assoc. of Reg. Bapt.",
religpew_baptist == 90 ~ "Other Baptist",
religpew_methodist == 1 ~ "United Methodist",
religpew_methodist == 2 ~ "Free Methodist",
religpew_methodist == 3 ~ "African Methodist Episcopal",
religpew_methodist == 4 ~ "AME - Zion",
religpew_methodist == 5 ~ "Christian Methodist Episcopal",
religpew_methodist == 90 ~ "Other Methodist",
religpew_nondenom == 1 ~ "Nondenom Evangelical",
religpew_nondenom == 2 ~ "Nondenom Fundamentalist",
religpew_nondenom == 3 ~ "Nondenom Charismatic",
religpew_nondenom == 4 ~ "Interdenominational",
religpew_nondenom == 5 ~ "Community Church",
religpew_nondenom == 90 ~ "Other Nondenom",
religpew_lutheran == 1 ~ "ELCA",
religpew_lutheran == 2 ~ "Lutheran - Missouri Synod",
religpew_lutheran == 3 ~ "Lutheran - Wisconsin Synod",
religpew_lutheran == 4 ~ "Other Lutheran",
religpew_presby == 1 ~ "PCUSA",
religpew_presby == 2 ~ "PCA",
religpew_presby == 3 ~ "Associated Reformed Presbyterian",
religpew_presby == 4 ~ "Cumberland Presbyterian",
religpew_presby == 5 ~ "Orthodox Presbyterian",
religpew_presby == 6 ~ "Evangelical Presbyterian",
religpew_presby == 90 ~ "Other Presbyterian",
religpew_pentecost == 1 ~ "Assemblies of God",
religpew_pentecost == 2 ~ "Church of God Cleveland TN",
religpew_pentecost == 3 ~ "Four Square Gospel",
religpew_pentecost == 4 ~ "Pentecostal Church of God",
religpew_pentecost == 5 ~ "Pentecostal Holiness Church",
religpew_pentecost == 6 ~ "Church of God in Christ",
religpew_pentecost == 7 ~ "Church of God of the Apostolic Faith",
religpew_pentecost == 8 ~ "Assembly of Christian Churches",
religpew_pentecost == 9 ~ "Apostolic Christian",
religpew_pentecost == 90 ~ "Other Pentecostal",
religpew_episcop == 1 ~ "ECUSA",
religpew_episcop == 2 ~ "Church of England",
religpew_episcop == 3 ~ "Anglican Orthodox",
religpew_episcop == 4 ~ "Reformed Episcopal",
religpew_episcop == 90 ~ "Other Episcopal",
religpew_christian == 1 ~ "Church of Christ",
religpew_christian == 2 ~ "Disciples of Christ",
religpew_christian == 3 ~ "Christian Church",
religpew_christian == 90 ~ "Other Christian Church",
religpew_congreg == 1 ~ "United Church of Christ",
religpew_congreg == 2 ~ "Conservative Cong. Christian",
religpew_congreg == 3 ~ "National Assoc. of Cons. Cong.",
religpew_congreg == 90 ~ "Other Cong.",
religpew_holiness == 1 ~ "Church of the Nazarene",
religpew_holiness == 2 ~ "Wesleyan Church",
religpew_holiness == 4 ~ "Christian and Missionary Alliance",
religpew_holiness == 5 ~ "Church of God",
religpew_holiness == 6 ~ "Salvation Army",
religpew_reformed == 1 ~ "Reformed Church in America",
religpew_reformed == 2 ~ "Christian Reformed",
religpew_reformed == 90 ~ "Other Reformed",
religpew_advent == 1 ~ "Seventh Day Adventist",
# religpew_advent == 2 ~ "Church of God",
religpew_advent == 3 ~ "Advent Christian",
religpew_advent == 90 ~ "Other Adventist",
religpew_jewish == 1 ~ "Reformed Jew",
religpew_jewish == 2 ~ "Conservative Jew",
religpew_jewish == 3 ~ "Orthodox Jew",
religpew_jewish == 4 ~ "Reconstructionist Jew",
religpew_jewish == 90 ~ "Other Jew",
religpew_muslim == 1 ~ "Sunni Muslim",
religpew_muslim == 2 ~ "Shia Muslim",
religpew_muslim == 3 ~ "Nation of Islam")) %>%
mutate(age = 2018 - birthyr) %>%
group_by(trad) %>%
mean_ci(age, wt = commonweight) %>%
filter(n > 300) %>%
arrange(-mean) %>%
na.omit()
gg %>%
mutate(mean = round(mean, 1)) %>%
ggplot(., aes(x = reorder(trad, mean), y = mean, fill = mean)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_gradient(low = "#eaafc8", high = "#654ea3") +
theme_rb() +
geom_text(aes(y = 2, label = mean), position = position_dodge(width = .9), size = 3, family = "font") +
error_bar() +
theme(plot.title = element_text(size = 12)) +
# geom_hline(yintercept = .317, linetype = "twodash") +
labs(x = "", y = "", title = "Average Age of Religious Traditions", caption = "@ryanburge\nData: CCES 2018") +
ggsave("E://age_trads_cces2018.png", type = "cairo-png", width = 6, height = 6)
e17 <- cces17 %>%
mutate(trad = frcode(religpew == 2 ~ "Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
religpew == 12 ~ "Something Else",
religpew_baptist == 1 ~ "Southern Baptist",
religpew_baptist == 2 ~ "ABCUSA",
religpew_baptist == 3 ~ "Natl. Baptist Convention",
religpew_baptist == 4 ~ "Progressive Baptist Convention",
religpew_baptist == 5 ~ "Independent Baptist",
religpew_baptist == 6 ~ "Baptist General Conference",
religpew_baptist == 7 ~ "Baptist Miss. Association",
religpew_baptist == 8 ~ "Conservative Bapt. Association",
religpew_baptist == 9 ~ "Free Will Baptist",
religpew_baptist == 10 ~ "Gen. Assoc. of Reg. Bapt.",
religpew_baptist == 90 ~ "Other Baptist",
religpew_methodist == 1 ~ "United Methodist",
religpew_methodist == 2 ~ "Free Methodist",
religpew_methodist == 3 ~ "African Methodist Episcopal",
religpew_methodist == 4 ~ "AME - Zion",
religpew_methodist == 5 ~ "Christian Methodist Episcopal",
religpew_methodist == 90 ~ "Other Methodist",
religpew_nondenom == 1 ~ "Nondenom Evangelical",
religpew_nondenom == 2 ~ "Nondenom Fundamentalist",
religpew_nondenom == 3 ~ "Nondenom Charismatic",
religpew_nondenom == 4 ~ "Interdenominational",
religpew_nondenom == 5 ~ "Community Church",
religpew_nondenom == 90 ~ "Other Nondenom",
religpew_lutheran == 1 ~ "ELCA",
religpew_lutheran == 2 ~ "Lutheran - Missouri Synod",
religpew_lutheran == 3 ~ "Lutheran - Wisconsin Synod",
religpew_lutheran == 4 ~ "Other Lutheran",
religpew_presby == 1 ~ "PCUSA",
religpew_presby == 2 ~ "PCA",
religpew_presby == 3 ~ "Associated Reformed Presbyterian",
religpew_presby == 4 ~ "Cumberland Presbyterian",
religpew_presby == 5 ~ "Orthodox Presbyterian",
religpew_presby == 6 ~ "Evangelical Presbyterian",
religpew_presby == 90 ~ "Other Presbyterian",
religpew_pentecost == 1 ~ "Assemblies of God",
religpew_pentecost == 2 ~ "Church of God Cleveland TN",
religpew_pentecost == 3 ~ "Four Square Gospel",
religpew_pentecost == 4 ~ "Pentecostal Church of God",
religpew_pentecost == 5 ~ "Pentecostal Holiness Church",
religpew_pentecost == 6 ~ "Church of God in Christ",
religpew_pentecost == 7 ~ "Church of God of the Apostolic Faith",
religpew_pentecost == 8 ~ "Assembly of Christian Churches",
religpew_pentecost == 9 ~ "Apostolic Christian",
religpew_pentecost == 90 ~ "Other Pentecostal",
religpew_episcop == 1 ~ "ECUSA",
religpew_episcop == 2 ~ "Church of England",
religpew_episcop == 3 ~ "Anglican Orthodox",
religpew_episcop == 4 ~ "Reformed Episcopal",
religpew_episcop == 90 ~ "Other Episcopal",
religpew_christian == 1 ~ "Church of Christ",
religpew_christian == 2 ~ "Disciples of Christ",
religpew_christian == 3 ~ "Christian Church",
religpew_christian == 90 ~ "Other Christian Church",
religpew_congreg == 1 ~ "United Church of Christ",
religpew_congreg == 2 ~ "Conservative Cong. Christian",
religpew_congreg == 3 ~ "National Assoc. of Cons. Cong.",
religpew_congreg == 90 ~ "Other Cong.",
religpew_holiness == 1 ~ "Church of the Nazarene",
religpew_holiness == 2 ~ "Wesleyan Church",
religpew_holiness == 4 ~ "Christian and Missionary Alliance",
religpew_holiness == 5 ~ "Church of God",
religpew_holiness == 6 ~ "Salvation Army",
religpew_reformed == 1 ~ "Reformed Church in America",
religpew_reformed == 2 ~ "Christian Reformed",
religpew_reformed == 90 ~ "Other Reformed",
religpew_advent == 1 ~ "Seventh Day Adventist",
# religpew_advent == 2 ~ "Church of God",
religpew_advent == 3 ~ "Advent Christian",
religpew_advent == 90 ~ "Other Adventist",
religpew_jewish == 1 ~ "Reformed Jew",
religpew_jewish == 2 ~ "Conservative Jew",
religpew_jewish == 3 ~ "Orthodox Jew",
religpew_jewish == 4 ~ "Reconstructionist Jew",
religpew_jewish == 90 ~ "Other Jew",
religpew_muslim == 1 ~ "Sunni Muslim",
religpew_muslim == 2 ~ "Shia Muslim",
religpew_muslim == 3 ~ "Nation of Islam")) %>%
mutate(age = 2017 - birthyr) %>%
select(trad, age)
e18 <- cces18 %>%
mutate(trad = frcode(religpew == 2 ~ "Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
religpew == 12 ~ "Something Else",
religpew_baptist == 1 ~ "Southern Baptist",
religpew_baptist == 2 ~ "ABCUSA",
religpew_baptist == 3 ~ "Natl. Baptist Convention",
religpew_baptist == 4 ~ "Progressive Baptist Convention",
religpew_baptist == 5 ~ "Independent Baptist",
religpew_baptist == 6 ~ "Baptist General Conference",
religpew_baptist == 7 ~ "Baptist Miss. Association",
religpew_baptist == 8 ~ "Conservative Bapt. Association",
religpew_baptist == 9 ~ "Free Will Baptist",
religpew_baptist == 10 ~ "Gen. Assoc. of Reg. Bapt.",
religpew_baptist == 90 ~ "Other Baptist",
religpew_methodist == 1 ~ "United Methodist",
religpew_methodist == 2 ~ "Free Methodist",
religpew_methodist == 3 ~ "African Methodist Episcopal",
religpew_methodist == 4 ~ "AME - Zion",
religpew_methodist == 5 ~ "Christian Methodist Episcopal",
religpew_methodist == 90 ~ "Other Methodist",
religpew_nondenom == 1 ~ "Nondenom Evangelical",
religpew_nondenom == 2 ~ "Nondenom Fundamentalist",
religpew_nondenom == 3 ~ "Nondenom Charismatic",
religpew_nondenom == 4 ~ "Interdenominational",
religpew_nondenom == 5 ~ "Community Church",
religpew_nondenom == 90 ~ "Other Nondenom",
religpew_lutheran == 1 ~ "ELCA",
religpew_lutheran == 2 ~ "Lutheran - Missouri Synod",
religpew_lutheran == 3 ~ "Lutheran - Wisconsin Synod",
religpew_lutheran == 4 ~ "Other Lutheran",
religpew_presby == 1 ~ "PCUSA",
religpew_presby == 2 ~ "PCA",
religpew_presby == 3 ~ "Associated Reformed Presbyterian",
religpew_presby == 4 ~ "Cumberland Presbyterian",
religpew_presby == 5 ~ "Orthodox Presbyterian",
religpew_presby == 6 ~ "Evangelical Presbyterian",
religpew_presby == 90 ~ "Other Presbyterian",
religpew_pentecost == 1 ~ "Assemblies of God",
religpew_pentecost == 2 ~ "Church of God Cleveland TN",
religpew_pentecost == 3 ~ "Four Square Gospel",
religpew_pentecost == 4 ~ "Pentecostal Church of God",
religpew_pentecost == 5 ~ "Pentecostal Holiness Church",
religpew_pentecost == 6 ~ "Church of God in Christ",
religpew_pentecost == 7 ~ "Church of God of the Apostolic Faith",
religpew_pentecost == 8 ~ "Assembly of Christian Churches",
religpew_pentecost == 9 ~ "Apostolic Christian",
religpew_pentecost == 90 ~ "Other Pentecostal",
religpew_episcop == 1 ~ "ECUSA",
religpew_episcop == 2 ~ "Church of England",
religpew_episcop == 3 ~ "Anglican Orthodox",
religpew_episcop == 4 ~ "Reformed Episcopal",
religpew_episcop == 90 ~ "Other Episcopal",
religpew_christian == 1 ~ "Church of Christ",
religpew_christian == 2 ~ "Disciples of Christ",
religpew_christian == 3 ~ "Christian Church",
religpew_christian == 90 ~ "Other Christian Church",
religpew_congreg == 1 ~ "United Church of Christ",
religpew_congreg == 2 ~ "Conservative Cong. Christian",
religpew_congreg == 3 ~ "National Assoc. of Cons. Cong.",
religpew_congreg == 90 ~ "Other Cong.",
religpew_holiness == 1 ~ "Church of the Nazarene",
religpew_holiness == 2 ~ "Wesleyan Church",
religpew_holiness == 4 ~ "Christian and Missionary Alliance",
religpew_holiness == 5 ~ "Church of God",
religpew_holiness == 6 ~ "Salvation Army",
religpew_reformed == 1 ~ "Reformed Church in America",
religpew_reformed == 2 ~ "Christian Reformed",
religpew_reformed == 90 ~ "Other Reformed",
religpew_advent == 1 ~ "Seventh Day Adventist",
# religpew_advent == 2 ~ "Church of God",
religpew_advent == 3 ~ "Advent Christian",
religpew_advent == 90 ~ "Other Adventist",
religpew_jewish == 1 ~ "Reformed Jew",
religpew_jewish == 2 ~ "Conservative Jew",
religpew_jewish == 3 ~ "Orthodox Jew",
religpew_jewish == 4 ~ "Reconstructionist Jew",
religpew_jewish == 90 ~ "Other Jew",
religpew_muslim == 1 ~ "Sunni Muslim",
religpew_muslim == 2 ~ "Shia Muslim",
religpew_muslim == 3 ~ "Nation of Islam")) %>%
mutate(age = 2018 - birthyr) %>%
select(trad, age)
e19 <- cces19 %>%
mutate(trad = frcode(religpew == 2 ~ "Catholic",
religpew == 3 ~ "Mormon",
religpew == 4 ~ "Orthodox",
religpew == 7 ~ "Buddhist",
religpew == 8 ~ "Hindu",
religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular",
religpew == 12 ~ "Something Else",
religpew_baptist == 1 ~ "Southern Baptist",
religpew_baptist == 2 ~ "ABCUSA",
religpew_baptist == 3 ~ "Natl. Baptist Convention",
religpew_baptist == 4 ~ "Progressive Baptist Convention",
religpew_baptist == 5 ~ "Independent Baptist",
religpew_baptist == 6 ~ "Baptist General Conference",
religpew_baptist == 7 ~ "Baptist Miss. Association",
religpew_baptist == 8 ~ "Conservative Bapt. Association",
religpew_baptist == 9 ~ "Free Will Baptist",
religpew_baptist == 10 ~ "Gen. Assoc. of Reg. Bapt.",
religpew_baptist == 90 ~ "Other Baptist",
religpew_methodist == 1 ~ "United Methodist",
religpew_methodist == 2 ~ "Free Methodist",
religpew_methodist == 3 ~ "African Methodist Episcopal",
religpew_methodist == 4 ~ "AME - Zion",
religpew_methodist == 5 ~ "Christian Methodist Episcopal",
religpew_methodist == 90 ~ "Other Methodist",
religpew_nondenom == 1 ~ "Nondenom Evangelical",
religpew_nondenom == 2 ~ "Nondenom Fundamentalist",
religpew_nondenom == 3 ~ "Nondenom Charismatic",
religpew_nondenom == 4 ~ "Interdenominational",
religpew_nondenom == 5 ~ "Community Church",
religpew_nondenom == 90 ~ "Other Nondenom",
religpew_lutheran == 1 ~ "ELCA",
religpew_lutheran == 2 ~ "Lutheran - Missouri Synod",
religpew_lutheran == 3 ~ "Lutheran - Wisconsin Synod",
religpew_lutheran == 4 ~ "Other Lutheran",
religpew_presby == 1 ~ "PCUSA",
religpew_presby == 2 ~ "PCA",
religpew_presby == 3 ~ "Associated Reformed Presbyterian",
religpew_presby == 4 ~ "Cumberland Presbyterian",
religpew_presby == 5 ~ "Orthodox Presbyterian",
religpew_presby == 6 ~ "Evangelical Presbyterian",
religpew_presby == 90 ~ "Other Presbyterian",
religpew_pentecost == 1 ~ "Assemblies of God",
religpew_pentecost == 2 ~ "Church of God Cleveland TN",
religpew_pentecost == 3 ~ "Four Square Gospel",
religpew_pentecost == 4 ~ "Pentecostal Church of God",
religpew_pentecost == 5 ~ "Pentecostal Holiness Church",
religpew_pentecost == 6 ~ "Church of God in Christ",
religpew_pentecost == 7 ~ "Church of God of the Apostolic Faith",
religpew_pentecost == 8 ~ "Assembly of Christian Churches",
religpew_pentecost == 9 ~ "Apostolic Christian",
religpew_pentecost == 90 ~ "Other Pentecostal",
religpew_episcop == 1 ~ "ECUSA",
religpew_episcop == 2 ~ "Church of England",
religpew_episcop == 3 ~ "Anglican Orthodox",
religpew_episcop == 4 ~ "Reformed Episcopal",
religpew_episcop == 90 ~ "Other Episcopal",
religpew_christian == 1 ~ "Church of Christ",
religpew_christian == 2 ~ "Disciples of Christ",
religpew_christian == 3 ~ "Christian Church",
religpew_christian == 90 ~ "Other Christian Church",
religpew_congreg == 1 ~ "United Church of Christ",
religpew_congreg == 2 ~ "Conservative Cong. Christian",
religpew_congreg == 3 ~ "National Assoc. of Cons. Cong.",
religpew_congreg == 90 ~ "Other Cong.",
religpew_holiness == 1 ~ "Church of the Nazarene",
religpew_holiness == 2 ~ "Wesleyan Church",
religpew_holiness == 4 ~ "Christian and Missionary Alliance",
religpew_holiness == 5 ~ "Church of God",
religpew_holiness == 6 ~ "Salvation Army",
religpew_reformed == 1 ~ "Reformed Church in America",
religpew_reformed == 2 ~ "Christian Reformed",
religpew_reformed == 90 ~ "Other Reformed",
religpew_advent == 1 ~ "Seventh Day Adventist",
# religpew_advent == 2 ~ "Church of God",
religpew_advent == 3 ~ "Advent Christian",
religpew_advent == 90 ~ "Other Adventist",
religpew_jewish == 1 ~ "Reformed Jew",
religpew_jewish == 2 ~ "Conservative Jew",
religpew_jewish == 3 ~ "Orthodox Jew",
religpew_jewish == 4 ~ "Reconstructionist Jew",
religpew_jewish == 90 ~ "Other Jew",
religpew_muslim == 1 ~ "Sunni Muslim",
religpew_muslim == 2 ~ "Shia Muslim",
religpew_muslim == 3 ~ "Nation of Islam")) %>%
mutate(age = 2019 - birthyr) %>%
select(trad, age)
bind3 <- bind_rows(e17, e18, e19) %>%
na.omit()
mode <- function(codes){
which.max(tabulate(codes))
}
md <- graph %>%
group_by(trad) %>%
summarise(mode = mode(age)) %>%
arrange(-mode)
jj <- graph %>%
ct(trad)
graph <- left_join(md, jj) %>%
filter(n > 400)
graph %>%
ggplot(., aes(x = reorder(trad, mode), y = mode, fill = mode)) +
geom_col(color = "black") +
coord_flip() +
scale_fill_gradient(low = "#eaafc8", high = "#654ea3") +
theme_rb() +
geom_text(aes(y = 2, label = mode), position = position_dodge(width = .9), size = 3, family = "font") +
theme(plot.title = element_text(size = 12)) +
# geom_hline(yintercept = .317, linetype = "twodash") +
labs(x = "", y = "", title = "Modal Age of Religious Traditions", caption = "@ryanburge\nData: CCES 2017-2019") +
ggsave("E://mode_age_trads_cces2018.png", type = "cairo-png", width = 6, height = 6)
bind3 <- left_join(bind3, jj)
mean <- bind3 %>%
group_by(trad) %>%
mean_ci(age) %>%
select(trad, mean)
bind3 <- left_join(bind3, mean)
bind3 %>%
filter(n > 750) %>%
ggplot(., aes(x = age, y = reorder(trad, -mean), fill = trad)) +
geom_density_ridges(scale = 8, size = 0.25, rel_min_height = 0.03, quantile_lines=TRUE,
quantile_fun=function(x,...)mean(x), alpha = .5) +
theme_rb() +
scale_fill_tableau(palette = "Tableau 20") +
labs(x = "Age", y = "Religious Tradition", title = "Age Distribution of Religious Traditions", caption = "@ryanburge\nData: CCES 2017-2019") +
ggsave("E://ridges_cces.png", type = "cairo-png", height = 6)
cen00 <- read_dta("C://Users/ryanb/Dropbox/data/relcen2000.dta")
cen10 <- read_dta("D://relcensus.dta")
cen00 <- cen00 %>%
select(fips = fip, cong00 = episccg, people00 = episcad, rate00 = episcrt)
cen10 <- cen10 %>%
select(fips, cong10 = eccng, people10 = ecadh, rate10 = ecrate)
graph <- left_join(cen00, cen10)
graph <- graph %>%
mutate(ratechange = rate00 - rate10) %>%
mutate(congchange = cong00 - cong10) %>%
mutate(adchange = people00 - people10)
graph <- graph %>%
mutate(gainloss = frcode(adchange < 0 ~ "Gained Members",
adchange > 0 ~ "Lost Members")) %>%
filter(gainloss != "NA")
territories_counties <- get_urbn_map(map = "territories_counties")
territories_counties <- territories_counties %>%
mutate(fips = as.numeric(county_fips))
joined <- left_join(territories_counties, graph)
joined %>%
filter(adchange != "NA") %>%
filter(adchange != "No Data") %>%
ggplot(aes(long, lat, group = group, fill = gainloss)) +
geom_polygon(color = "black", size = 0.05) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
labs(title = "Change in Number of Episcopalians (2000-2010)", caption = "Data: 2000 + 2010 Religious Census", fill = "") +
theme(legend.title = element_text(), legend.key.width = unit(.5, "in")) +
urbnthemes::theme_urbn_map() +
theme(plot.title = element_text(size=16, family= "font", face= "bold")) +
theme(plot.caption = element_text(size = 16, family="font")) +
theme(text=element_text(size=45, family="font")) +
ggsave("E://epis_map.png", type = "cairo-png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment