/ct_selection_untitled-E13E74EC.R Secret
Created
May 3, 2024 20:27
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(rio) | |
library(janitor) | |
clergy <- import("E://data/clergy_old.dta") %>% clean_names() | |
gg <- clergy %>% | |
ct(first_name) %>% | |
arrange(-n) %>% | |
head(20) | |
gg %>% | |
ggplot(., aes(x = reorder(first_name, n), y = n, fill = first_name)) + | |
geom_col(color = "black") + | |
coord_flip() + | |
theme_rb() + | |
geom_text(aes(y = n + 17, label = ifelse(n < 100, n, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
geom_text(aes(y = n + 25, label = ifelse(n > 100, n, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680")) + | |
labs(x = "", y = "", title = "Most Popular First Names of Colonial Ministers", caption = "@ryanburge + @religiondata\nData: Clergymen in Revolutionary America (1763-1783)") | |
save("old_clergy_first_names.png") | |
colony <- clergy %>% | |
mutate(colony = str_replace_all(colony, "Conneticut", "Connecticut")) %>% | |
mutate(colony = str_replace_all(colony, "Conneticutt", "Connecticut")) %>% | |
mutate(colony = str_replace_all(colony, "Connecticutt", "Connecticut")) %>% | |
mutate(colony = str_replace_all(colony, "Jew Jersey", "New Jersey")) %>% | |
mutate(colony = str_replace_all(colony, "Maine (Massachusetts)", "Maine")) %>% | |
mutate(colony = str_replace_all(colony, "Vermont (New York)", "Vermont")) %>% | |
mutate(colony = str_replace_all(colony, "New Hampture", "New Hampshire")) %>% | |
mutate(colony = str_replace_all(colony, "Road Island", "Rhode Island")) %>% | |
ct(colony) %>% | |
filter(n > 10) %>% | |
mutate(id = colony) | |
fips <- data.frame( | |
stringsAsFactors = FALSE, | |
id = c("Alabama","Alaska","Arizona", | |
"Arkansas","California","Colorado","Connecticut", | |
"Delaware","Florida","Georgia","Hawaii","Idaho", | |
"Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana", | |
"Maine","Maryland","Massachusetts","Michigan", | |
"Minnesota","Mississippi","Missouri","Montana","Nebraska", | |
"Nevada","New Hampshire","New Jersey","New Mexico", | |
"New York","North Carolina","North Dakota","Ohio", | |
"Oklahoma","Oregon","Pennsylvania","Rhode Island", | |
"South Carolina","South Dakota","Tennessee","Texas","Utah", | |
"Vermont","Virginia","Washington","West Virginia", | |
"Wisconsin","Wyoming","American Samoa","Guam", | |
"Northern Mariana Islands","Puerto Rico","Virgin Islands"), | |
abb = c("AL","AK","AZ","AR","CA", | |
"CO","CT","DE","FL","GA","HI","ID","IL","IN","IA", | |
"KS","KY","LA","ME","MD","MA","MI","MN","MS", | |
"MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND", | |
"OH","OK","OR","PA","RI","SC","SD","TN","TX", | |
"UT","VT","VA","WA","WV","WI","WY","AS","GU","MP", | |
"PR","VI"), | |
sfips = c("01","02","04","05","06", | |
"08","09","10","12","13","15","16","17","18","19", | |
"20","21","22","23","24","25","26","27","28", | |
"29","30","31","32","33","34","35","36","37","38", | |
"39","40","41","42","44","45","46","47","48", | |
"49","50","51","53","54","55","56","60","66","69", | |
"72","78") | |
) | |
fips$sfips <- as.numeric(fips$sfips) | |
graph <- left_join(colony, fips) | |
graph$id <- tolower(graph$id) | |
library(fiftystater) | |
data("fifty_states") | |
mapp <- left_join(fifty_states, graph, by = c("id")) %>% as_tibble() %>% filter(colony != "NA") | |
map <- mapp %>% | |
mutate(bins = frcode(n >= 300 ~ "a", | |
n < 299 & n > 100~ "b", | |
n < 10 ~ "c")) | |
centers <- read_csv("D://state_centers_inset.csv") %>% rename(id = full) | |
centers$id <- tolower(centers$id) | |
centers <- left_join(map, centers, by = c("id")) %>% as_tibble() | |
centers <- centers %>% distinct(id, .keep_all = TRUE) | |
fips <- data.frame( | |
stringsAsFactors = FALSE, | |
id = c("Alabama","Alaska","Arizona", | |
"Arkansas","California","Colorado","Connecticut", | |
"Delaware","Florida","Georgia","Hawaii","Idaho", | |
"Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana", | |
"Maine","Maryland","Massachusetts","Michigan", | |
"Minnesota","Mississippi","Missouri","Montana","Nebraska", | |
"Nevada","New Hampshire","New Jersey","New Mexico", | |
"New York","North Carolina","North Dakota","Ohio", | |
"Oklahoma","Oregon","Pennsylvania","Rhode Island", | |
"South Carolina","South Dakota","Tennessee","Texas","Utah", | |
"Vermont","Virginia","Washington","West Virginia", | |
"Wisconsin","Wyoming","American Samoa","Guam", | |
"Northern Mariana Islands","Puerto Rico","Virgin Islands"), | |
abb = c("AL","AK","AZ","AR","CA", | |
"CO","CT","DE","FL","GA","HI","ID","IL","IN","IA", | |
"KS","KY","LA","ME","MD","MA","MI","MN","MS", | |
"MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND", | |
"OH","OK","OR","PA","RI","SC","SD","TN","TX", | |
"UT","VT","VA","WA","WV","WI","WY","AS","GU","MP", | |
"PR","VI"), | |
FIPS = c("01","02","04","05","06", | |
"08","09","10","12","13","15","16","17","18","19", | |
"20","21","22","23","24","25","26","27","28", | |
"29","30","31","32","33","34","35","36","37","38", | |
"39","40","41","42","44","45","46","47","48", | |
"49","50","51","53","54","55","56","60","66","69", | |
"72","78") | |
) | |
centers <- left_join(centers, fips) | |
library(ggrepel) | |
map %>% | |
ggplot(., mapping = aes(x = long, y = lat, group = group, fill = bins)) + | |
geom_polygon(color = "black", linewidth = 0.1) + | |
coord_map(projection = "albers", lat0 = 41, lat1 = 44) + | |
scale_fill_manual(values = c("#423b74", "#6454c9", "#b2b8ef")) + | |
ggrepel::geom_label_repel(data = centers, | |
aes(x = longitude, y = latitude, label = n, group = group), size = 7, fill = "white", | |
seed = 1002, family = "font", force = .003, show.legend = FALSE) + | |
theme_rb() + | |
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.position = "none", | |
plot.title = element_text(size = 22), | |
strip.text = element_text(size = 24), | |
legend.text = element_text(size = 24)) + | |
labs(title = "Number of Clergy Recorded in Each Colony/State", caption = "@ryanburge + @religiondata\nData: Clergymen in Revolutionary America (1763-1783)") | |
save("clergy_map_history.png", ht = 10) | |
gg <- clergy %>% ct(denomination) %>% arrange(-n) %>% head(10) | |
gg %>% | |
ggplot(., aes(x = reorder(denomination, n), y = n, fill = denomination)) + | |
geom_col(color = "black") + | |
coord_flip() + | |
theme_rb() + | |
geom_text(aes(y = n + 40, label = ifelse(n < 100, n, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
geom_text(aes(y = n + 65, label = ifelse(n > 100, n, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1")) + | |
labs(x = "", y = "", title = "Most Popular Denominations Among Ministers, 1763-1783", caption = "@ryanburge + @religiondata\nData: Clergymen in Revolutionary America (1763-1783)") | |
save("old_clergy_denoms.png") | |
colony <- clergy %>% | |
group_by(colony, denomination) %>% # Group data by colony and denomination | |
summarise(count = n(), .groups = "drop") %>% # Count occurrences | |
arrange(colony, desc(count)) %>% # Arrange by colony and descending count | |
group_by(colony) %>% | |
slice(1) %>% filter(count > 10) %>% | |
select(id = colony, denomination) | |
fips <- data.frame( | |
stringsAsFactors = FALSE, | |
id = c("Alabama","Alaska","Arizona", | |
"Arkansas","California","Colorado","Connecticut", | |
"Delaware","Florida","Georgia","Hawaii","Idaho", | |
"Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana", | |
"Maine","Maryland","Massachusetts","Michigan", | |
"Minnesota","Mississippi","Missouri","Montana","Nebraska", | |
"Nevada","New Hampshire","New Jersey","New Mexico", | |
"New York","North Carolina","North Dakota","Ohio", | |
"Oklahoma","Oregon","Pennsylvania","Rhode Island", | |
"South Carolina","South Dakota","Tennessee","Texas","Utah", | |
"Vermont","Virginia","Washington","West Virginia", | |
"Wisconsin","Wyoming","American Samoa","Guam", | |
"Northern Mariana Islands","Puerto Rico","Virgin Islands"), | |
abb = c("AL","AK","AZ","AR","CA", | |
"CO","CT","DE","FL","GA","HI","ID","IL","IN","IA", | |
"KS","KY","LA","ME","MD","MA","MI","MN","MS", | |
"MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND", | |
"OH","OK","OR","PA","RI","SC","SD","TN","TX", | |
"UT","VT","VA","WA","WV","WI","WY","AS","GU","MP", | |
"PR","VI"), | |
sfips = c("01","02","04","05","06", | |
"08","09","10","12","13","15","16","17","18","19", | |
"20","21","22","23","24","25","26","27","28", | |
"29","30","31","32","33","34","35","36","37","38", | |
"39","40","41","42","44","45","46","47","48", | |
"49","50","51","53","54","55","56","60","66","69", | |
"72","78") | |
) | |
fips$sfips <- as.numeric(fips$sfips) | |
graph <- left_join(colony, fips) | |
graph$id <- tolower(graph$id) | |
library(fiftystater) | |
data("fifty_states") | |
mapp <- left_join(fifty_states, graph, by = c("id")) %>% as_tibble() %>% filter(denomination != "NA") | |
centers <- read_csv("D://state_centers_inset.csv") %>% rename(id = full) | |
centers$id <- tolower(centers$id) | |
centers <- left_join(map, centers, by = c("id")) %>% as_tibble() | |
centers <- centers %>% distinct(id, .keep_all = TRUE) | |
fips <- data.frame( | |
stringsAsFactors = FALSE, | |
id = c("Alabama","Alaska","Arizona", | |
"Arkansas","California","Colorado","Connecticut", | |
"Delaware","Florida","Georgia","Hawaii","Idaho", | |
"Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana", | |
"Maine","Maryland","Massachusetts","Michigan", | |
"Minnesota","Mississippi","Missouri","Montana","Nebraska", | |
"Nevada","New Hampshire","New Jersey","New Mexico", | |
"New York","North Carolina","North Dakota","Ohio", | |
"Oklahoma","Oregon","Pennsylvania","Rhode Island", | |
"South Carolina","South Dakota","Tennessee","Texas","Utah", | |
"Vermont","Virginia","Washington","West Virginia", | |
"Wisconsin","Wyoming","American Samoa","Guam", | |
"Northern Mariana Islands","Puerto Rico","Virgin Islands"), | |
abb = c("AL","AK","AZ","AR","CA", | |
"CO","CT","DE","FL","GA","HI","ID","IL","IN","IA", | |
"KS","KY","LA","ME","MD","MA","MI","MN","MS", | |
"MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND", | |
"OH","OK","OR","PA","RI","SC","SD","TN","TX", | |
"UT","VT","VA","WA","WV","WI","WY","AS","GU","MP", | |
"PR","VI"), | |
FIPS = c("01","02","04","05","06", | |
"08","09","10","12","13","15","16","17","18","19", | |
"20","21","22","23","24","25","26","27","28", | |
"29","30","31","32","33","34","35","36","37","38", | |
"39","40","41","42","44","45","46","47","48", | |
"49","50","51","53","54","55","56","60","66","69", | |
"72","78") | |
) | |
centers <- left_join(centers, fips) | |
library(ggrepel) | |
mapp %>% | |
ggplot(., mapping = aes(x = long, y = lat, group = group, fill = denomination)) + | |
geom_polygon(color = "black", linewidth = 0.1) + | |
coord_map(projection = "albers", lat0 = 41, lat1 = 44) + | |
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1")) + | |
theme_rb() + | |
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.position = "left", | |
plot.title = element_text(size = 22), | |
strip.text = element_text(size = 24), | |
legend.text = element_text(size = 14)) + | |
labs(title = "Most Popular Denominations Among Clergy", caption = "@ryanburge + @religiondata\nData: Clergymen in Revolutionary America (1763-1783)") | |
save("clergy_map_history_denominations.png", ht = 10) | |
time <- clergy %>% | |
mutate(start = as.numeric(beginning_year)) %>% | |
mutate(end = as.numeric(ending_year)) %>% | |
mutate(time = end - start) %>% | |
filter(time >= 0) %>% | |
group_by(denomination) %>% | |
mean_ci(time) %>% | |
filter(n > 50) | |
time %>% | |
mutate(lab = round(mean, 1)) %>% | |
ggplot(., aes(x = reorder(denomination, mean), y = mean, fill = denomination)) + | |
geom_col(color = "black") + | |
coord_flip() + | |
theme_rb() + | |
geom_text(aes(y = mean + 1.2, label = ifelse(mean < 10, lab, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
geom_text(aes(y = mean + 1.5, label = ifelse(mean > 10, lab, "")), position = position_dodge(width = .9), size = 7, family = "font") + | |
scale_fill_manual(values = c("#033f63", "#28666e", "#e1e1e1", "#B5B682", "#FEDC97", "#7D3C98", "#5f2680", "#033f63", "#28666e", "#e1e1e1")) + | |
labs(x = "", y = "", title = "Average Tenure of Ministers, 1763-1783", caption = "@ryanburge + @religiondata\nData: Clergymen in Revolutionary America (1763-1783)") | |
save("old_clergy_experience_clergy.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment