Anusha Bishop, Nica Campbell, and Sangcheol Moon 2022-05-09
# hacky way to get a CA boundary shape file
state_ca <- get_acs(
geography = "state",
variables = "B19013_001",
state = "CA",
year = 2020,
geometry = TRUE)## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |== | 4% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |====================== | 31% | |====================== | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |==================================== | 51% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 100%
state <- state_ca[1]landfill <- read_excel("lmopdataca.xlsx", sheet = "LMOP_Database")
landfill_loc <- landfill %>% dplyr::select("Landfill ID", "Latitude", "Longitude", "Zip Code", "Landfill Name", "Current Landfill Status") %>% distinct()
landfill_loc <- na.omit(landfill_loc)
landfill_sf <- st_as_sf(landfill_loc, coords = c("Longitude", "Latitude"), crs = crs(state))# generate random points for use in making null distributions for comparisons
rand <- st_sample(state, 10000)
rand_sf <- st_as_sf(rand, crs = crs(state))
# function that will be used later to create a null distribution of values against which to compare the landfill distribution
sp_null <- function(i, rand_df, landfill_df){
sub_mean <- rand_df %>% sample_n(nrow(landfill_df)) %>% dplyr::select(-geometry) %>% summarise_all(mean, na.rm = TRUE)
return(sub_mean)
}ca_income <- get_acs(
geography = "tract",
variables = "B19013_001",
state = "CA",
year = 2020,
geometry = TRUE)## | | | 0% | |= | 1% | |= | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 27% | |==================== | 28% | |==================== | 29% | |===================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 60% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 78% | |======================================================== | 80% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |======================================================================| 100%
inc <- ca_income["estimate"]ggplot() +
ggtitle("Median Household Income (CA)") +
geom_sf(data = ca_income, aes(fill = estimate, color = estimate)) +
geom_sf(data = landfill_sf, fill = "#A2E4B8", col = "#008080", cex = 1, pch = 21, alpha = 0.9) +
scale_fill_viridis(option = "magma") +
scale_color_viridis(option = "magma") +
theme_few()A qualitative comparison of the distribution of incomes at landfill sites versus that at the random sites shows that the landfill locations have more higher income values than expected. Revisiting the map from before, this is probably because landfills are clustered around cities like LA where the average income is likely higher and landfills are less frequently found in less populated/lower income areas that probably aren’t producing as much trash over a smaller area like cities.
landfill_income <- st_join(landfill_sf, inc)
landfill_income_df <- as_tibble(landfill_income) %>% rename("Income" = "estimate")
rand_income <- st_join(rand_sf, inc)
rand_income_df <- as_tibble(rand_income) %>% rename("Income" = "estimate")
ggplot() +
ggtitle("Median Household Income (CA)") +
geom_histogram(data = rand_income_df, aes(x = Income, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_income_df, aes(x = Income, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_histogram(data = landfill_income_df, aes(x = Income, y = ..density.., fill = "Observed"), alpha = 0.5) +
geom_density(data = landfill_income_df, aes(x = Income, fill = "Observed"), col = "#ff9470", alpha = 0.5) +
scale_fill_manual(values = c("#330099", "#ff9470"), name = "") +
theme_few() +
theme(legend.position = c(0.9, 0.8), legend.key = element_rect(colour = "white"))This basically is a test to see if the mean income of the landfill sites is significantly different than the mean income expected if the sites were chosen randomly. As you can see from the plot the mean income at the landfill sites is significantly greater (p = 0) than that of the randomly chosen points. Of course, based on how the points were randomly sampled across California, this assumes that any point within the state could be a landfill site, which is probably not true.
rand_mean_income <- map_dfr(1:100, sp_null, rand_df = rand_income_df, landfill_df = landfill_income_df) %>% rename("mean" = "Income")
obs_mean_income <- landfill_income_df %>% summarize(mean(Income, na.rm = TRUE)) %>% rename("mean" = "mean(Income, na.rm = TRUE)")
ggplot() +
ggtitle("Median Household Income (CA)") +
geom_histogram(data = rand_mean_income, aes(x = mean, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_mean_income, aes(x = mean, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_vline(aes(xintercept = obs_mean_income$mean, col = "Observed"), lwd = 1.2) +
scale_fill_manual(values = c("#330099"), name = element_blank()) +
scale_colour_manual(values = c("#ff9470"), name = element_blank()) +
xlim(56000, 76000) +
theme_few() +
theme(legend.position = c(0.1, 0.7), legend.key = element_rect(colour = "white"))rand_income_df$group <- "random"
rand_income_df <- rand_income_df %>% rename("mean" = "Income") %>% dplyr::select("mean", "group")
landfill_income_df$group <- "observed"
landfill_mean_income <- landfill_income_df %>% rename("mean" = "Income") %>% dplyr::select("mean", "group")
raincloud_ca <- rbind(rand_income_df, landfill_mean_income)
ggplot(raincloud_ca, aes(x= group, y = mean, fill = group)) +
ggdist::stat_halfeye(adjust = .5, .width = 0, justification = -.2, point_colour = NA) +
geom_boxplot(width = .1, outlier.color = NA, alpha = .5) +
gghalves::geom_half_point(aes(color = group), side = "l", range_scale = .4, alpha = .3) +
labs(title = "California: Raincloud Plot (Landfill distribution)", y = "Median household income (CA)") How about in Texas? Average income is lower than California based on 2020 census by $12k, it is a economically growing states with the number of landfills above the US average.
state_tx <- get_acs(
geography = "state",
variables = "B19013_001",
state = "TX",
year = 2020,
geometry = TRUE)
Statetx <- state_tx[1]landfill_tx <- read_excel("lmopdatatx.xlsx", sheet = "LMOP Database")
landfill_tx_loc <- landfill_tx %>% dplyr::select("Landfill ID", "Latitude", "Longitude", "Zip Code", "Landfill Name", "Current Landfill Status") %>% distinct()
landfill_tx_loc <- na.omit(landfill_tx_loc)
landfill_tx_sf <- st_as_sf(landfill_tx_loc, coords = c("Longitude", "Latitude"), crs = crs(Statetx))#Median income for tx
tx_income <- get_acs(
geography = "tract",
variables = "B19013_001", #need to check
state = "TX", #need to check
year = 2020,
geometry = TRUE
)## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 20% | |============== | 21% | |=============== | 21% | |=============== | 22% | |================ | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |===================== | 31% | |====================== | 31% | |====================== | 32% | |======================= | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================= | 41% | |============================== | 42% | |============================== | 43% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================= | 64% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100%
inctx <- tx_income["estimate"]
landfill_tx_income <- st_join(landfill_tx_sf, inctx)
landfill_tx_income_df <- as_tibble(landfill_tx_income) %>% rename("Income" = "estimate")
ggplot() +
ggtitle("Median Household Income (TX)") +
geom_sf(data = tx_income, aes(fill = estimate, color = estimate)) +
geom_sf(data = landfill_tx_sf, fill = "#A2E4B8", col = "#008080", cex = 1, pch = 21, alpha = 0.9) +
scale_fill_viridis(option = "magma") +
scale_color_viridis(option = "magma") +
theme_few()# generate random points for use in making null distributions for comparisons
rand_tx <- st_sample(Statetx, 10000)
rand_tx_sf <- st_as_sf(rand_tx, crs = crs(Statetx))
rand_tx_income <- st_join(rand_tx_sf, inctx)
rand_tx_income_df <- as_tibble(rand_tx_income) %>% rename("Income" = "estimate")
ggplot() +
ggtitle("Median Household Income (TX)") +
geom_histogram(data = rand_tx_income_df, aes(x = Income, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_tx_income_df, aes(x = Income, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_histogram(data = landfill_tx_income_df, aes(x = Income, y = ..density.., fill = "Observed"), alpha = 0.5) +
geom_density(data = landfill_tx_income_df, aes(x = Income, fill = "Observed"), col = "#ff9470", alpha = 0.5) +
scale_fill_manual(values = c("#330099", "#ff9470"), name = "") +
theme_few() +
theme(legend.position = c(0.9, 0.8), legend.key = element_rect(colour = "white"))rand_mean_income_tx <- map_dfr(1:100, sp_null, rand_df = rand_tx_income_df, landfill_df = landfill_tx_income_df) %>% rename("mean" = "Income")
obs_mean_income_tx <- landfill_tx_income_df %>% summarize(mean(Income, na.rm = TRUE)) %>% rename("mean" = "mean(Income, na.rm = TRUE)")
ggplot() +
ggtitle("Median Household Income (TX)") +
geom_histogram(data = rand_mean_income_tx, aes(x = mean, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_mean_income_tx, aes(x = mean, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_vline(aes(xintercept = obs_mean_income_tx$mean, col = "Observed"), lwd = 1.2) +
scale_fill_manual(values = c("#330099"), name = element_blank()) +
scale_colour_manual(values = c("#ff9470"), name = element_blank()) +
xlim(56000, 76000) +
theme_few() +
theme(legend.position = c(0.1, 0.7), legend.key = element_rect(colour = "white"))rand_tx_income_df$group <- "random"
rand_tx_income_df <- rand_tx_income_df %>% rename("mean" = "Income") %>% dplyr::select("mean", "group")
landfill_tx_income_df$group <- "observed"
landfill_tx_mean_income <- landfill_tx_income_df %>% rename("mean" = "Income") %>% dplyr::select("mean", "group")
raincloud_tx_income <- rbind(rand_tx_income_df, landfill_tx_mean_income)
ggplot(raincloud_tx_income, aes(x= group, y = mean, fill = group)) +
ggdist::stat_halfeye(adjust = .5, .width = 0, justification = -.2, point_colour = NA) +
geom_boxplot(width = .1, outlier.color = NA, alpha = .5) +
gghalves::geom_half_point(aes(color = group), side = "l", range_scale = .4, alpha = .3) +
labs(title = "Texas: Raincloud Plot (Landfill distribution)", y = "Median household income (TX)") ca_race <- get_decennial(
geography = "tract",
state = "CA",
variables = c(
Hispanic = "P2_002N",
White = "P2_005N",
Black = "P2_006N",
Native = "P2_007N",
Asian = "P2_008N"
),
summary_var = "P2_001N",
year = 2020,
geometry = TRUE
) %>%
mutate(percent = 100 * (value / summary_value))
white_ca <- filter(ca_race, variable == "White")
white_ca <- white_ca ["percent"]ggplot() +
ggtitle("Percent White (CA)") +
geom_sf(data = white_ca, aes(fill = percent, color = percent)) +
geom_sf(data = landfill_sf, fill = "#A2E4B8", col = "#008080", cex = 1, pch = 21, alpha = 0.9) +
scale_fill_viridis(option = "magma") +
scale_color_viridis(option = "magma") +
theme_few()landfill_white <- st_join(landfill_sf, white_ca)
landfill_white_df <- as_tibble(landfill_white) %>% rename("PercentWhite" = "percent")
rand_white <- st_join(rand_sf, white_ca)
rand_white_df <- as_tibble(rand_white) %>% rename("PercentWhite" = "percent")
ggplot() +
ggtitle("Percent White (CA)") +
geom_histogram(data = rand_white_df, aes(x = PercentWhite, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_white_df, aes(x = PercentWhite, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_histogram(data = landfill_white_df, aes(x = PercentWhite, y = ..density.., fill = "Observed"), alpha = 0.5) +
geom_density(data = landfill_white_df, aes(x = PercentWhite, fill = "Observed"), col = "#ff9470", alpha = 0.5) +
scale_fill_manual(values = c("#330099", "#ff9470"), name = "") +
theme_few() +
theme(legend.position = c(0.1, 0.8), legend.key = element_rect(colour = "white"))This test is to see if the mean percent of White population of the landfill sites is significantly different than the mean percent of White expected if the sites were chosen randomly. As you can see from the plot the mean percent of White at the landfill sites is significantly lower than that of the randomly chosen points. (Again, the assumption that any point within the state could be a landfill site is not realistic.)
rand_mean_white <- map_dfr(1:100, sp_null, rand_df = rand_white_df, landfill_df = landfill_white_df) %>% rename("mean" = "PercentWhite")
obs_mean_white <- landfill_white_df %>% summarize(mean(PercentWhite, na.rm = TRUE)) %>% rename("mean" = "mean(PercentWhite, na.rm = TRUE)")
ggplot() +
ggtitle("Percent White (CA)") +
geom_histogram(data = rand_mean_white, aes(x = mean, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_mean_white, aes(x = mean, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_vline(aes(xintercept = obs_mean_white$mean, col = "Observed"), lwd = 1.2) +
scale_fill_manual(values = c("#330099"), name = element_blank()) +
scale_colour_manual(values = c("#ff9470"), name = element_blank()) +
xlim(45, 65) +
theme_few() +
theme(legend.position = c(0.9, 0.7), legend.key = element_rect(colour = "white"))rand_white_df$group <- "random"
rand_white_df <- rand_white_df %>% rename("mean" = "PercentWhite") %>% dplyr::select("mean", "group")
landfill_white_df$group <- "observed"
landfill_mean_white_df <- landfill_white_df %>% rename("mean" = "PercentWhite") %>% dplyr::select("mean", "group")
raincloud_race_ca <- rbind(rand_white_df, landfill_mean_white_df)
ggplot(raincloud_race_ca, aes(x= group, y = mean, fill = group)) +
ggdist::stat_halfeye(adjust = .5, .width = 0, justification = -.2, point_colour = NA) +
geom_boxplot(width = .1, outlier.color = NA, alpha = .5) +
gghalves::geom_half_point(aes(color = group), side = "l", range_scale = .4, alpha = .3) +
labs(title = "California: Raincloud Plot (Landfill distribution)", y = "Percent of White pop (CA)") tx_race <- get_decennial(
geography = "tract",
state = "TX",
variables = c(
Hispanic = "P2_002N",
White = "P2_005N",
Black = "P2_006N",
Native = "P2_007N",
Asian = "P2_008N"
),
summary_var = "P2_001N",
year = 2020,
geometry = TRUE
) %>%
mutate(percent = 100 * (value / summary_value))
white_tx <- filter(tx_race, variable == "White")
white_tx <- white_tx["percent"]ggplot() +
ggtitle("Percent White (TX)") +
geom_sf(data = white_tx, aes(fill = percent, color = percent)) +
geom_sf(data = landfill_tx_sf, fill = "#A2E4B8", col = "#008080", cex = 1, pch = 21, alpha = 0.9) +
scale_fill_viridis(option = "magma") +
scale_color_viridis(option = "magma") +
theme_few()landfill_tx_white <- st_join(landfill_tx_sf, white_tx)
landfill_tx_white_df <- as_tibble(landfill_tx_white) %>% rename("PercentWhite" = "percent")
rand_tx <- st_sample(Statetx, 10000)
rand_tx_sf <- st_as_sf(rand_tx, crs = crs(Statetx))
rand_tx_white <- st_join(rand_tx_sf, white_tx)
rand_tx_white_df <- as_tibble(rand_tx_white) %>% rename("PercentWhite" = "percent")
ggplot() +
ggtitle("Percent White (TX)") +
geom_histogram(data = rand_tx_white_df, aes(x = PercentWhite, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_tx_white_df, aes(x = PercentWhite, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_histogram(data = landfill_tx_white_df, aes(x = PercentWhite, y = ..density.., fill = "Observed"), alpha = 0.5) +
geom_density(data = landfill_tx_white_df, aes(x = PercentWhite, fill = "Observed"), col = "#ff9470", alpha = 0.5) +
scale_fill_manual(values = c("#330099", "#ff9470"), name = "") +
theme_few() +
theme(legend.position = c(0.1, 0.8), legend.key = element_rect(colour = "white"))As seen in the CA case, we found that the mean percent of White at the landfill sites is significantly lower than that of the randomly chosen points. (Again, the assumption that any point within the state could be a landfill site is not realistic.)
rand_tx_mean_white <- map_dfr(1:100, sp_null, rand_df = rand_tx_white_df, landfill_df = landfill_tx_white_df) %>% rename("mean" = "PercentWhite")
obs_tx_mean_white <- landfill_tx_white_df %>% summarize(mean(PercentWhite, na.rm = TRUE)) %>% rename("mean" = "mean(PercentWhite, na.rm = TRUE)")
ggplot() +
ggtitle("Percent White (TX)") +
geom_histogram(data = rand_tx_mean_white, aes(x = mean, y = ..density.., fill = "Null"), alpha = 0.5) +
geom_density(data = rand_tx_mean_white, aes(x = mean, fill = "Null"), col = "#330099", alpha = 0.5) +
geom_vline(aes(xintercept = obs_tx_mean_white$mean, col = "Observed"), lwd = 1.2) +
scale_fill_manual(values = c("#330099"), name = element_blank()) +
scale_colour_manual(values = c("#ff9470"), name = element_blank()) +
xlim(45, 65) +
theme_few() +
theme(legend.position = c(0.9, 0.7), legend.key = element_rect(colour = "white"))rand_tx_white_df$group <- "random"
rand_tx_white_df <- rand_tx_white_df %>% rename("mean" = "PercentWhite") %>% dplyr::select("mean", "group")
landfill_tx_white_df$group <- "observed"
landfill_tx_mean_white_df <- landfill_tx_white_df %>% rename("mean" = "PercentWhite") %>% dplyr::select("mean", "group")
raincloud_race_tx <- rbind(rand_tx_white_df, landfill_tx_mean_white_df)
ggplot(raincloud_race_tx, aes(x= group, y = mean, fill = group)) +
ggdist::stat_halfeye(adjust = .5, .width = 0, justification = -.2, point_colour = NA) +
geom_boxplot(width = .1, outlier.color = NA, alpha = .5) +
gghalves::geom_half_point(aes(color = group), side = "l", range_scale = .4, alpha = .3) +
labs(title = "Texas: Raincloud Plot (Landfill distribution)", y = "Percent of White pop (TX)") ## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======== | 11% | |========= | 12% | |========= | 13% | |========== | 14% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============= | 18% | |============= | 19% | |============== | 20% | |=============== | 21% | |=============== | 22% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 26% | |=================== | 26% | |=================== | 27% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |====================== | 31% | |====================== | 32% | |======================= | 33% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |=========================== | 38% | |============================ | 40% | |============================= | 41% | |============================= | 42% | |============================== | 43% | |=============================== | 44% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |================================== | 49% | |=================================== | 50% | |==================================== | 51% | |==================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |============================================= | 65% | |============================================== | 66% | |=============================================== | 67% | |================================================ | 68% | |================================================ | 69% | |================================================= | 70% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 77% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================== | 82% | |========================================================== | 83% | |=========================================================== | 84% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 90% | |================================================================ | 91% | |================================================================= | 92% | |================================================================= | 93% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 97% | |======================================================================| 100%