Use this code to help get you started on the midterm! You will more
than likely have to manipulate/standardize the variables to analyze the
data. Your midterm must include: -A minimum of 2 maps (the map that I
start you out with does not count) -At least one graph -At least two
functions from our geoprocessing units (get creative! note that using
more than one spatial operation counts as 2. The spatial operation used
in this code does not count) Please make note of where you use these
so I can find them -A 500 word write-up answering the following
questions: What were the results of your analysis? Where would
you build the new food pantry and why?
What challenges did you encountered in your work? *What data or
information is missing from this analysis? If you could include any
additional information, what would you include?
Data Sources: Zipcode Shapefile: Data.gov Zipcode Characteristics: Amerian Community Survey from data.census.gov Emergency Food Access Map: Broome County Food Council (addresses geocoded by geocod.io)
setwd("C:/Users/Donny/OneDrive/R studio/zip_codes/zip_codes")
Warning: The working directory was changed to C:/Users/Donny/OneDrive/R studio/zip_codes/zip_codes inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
library(sf)
Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(ggplot2)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
#library(urbnmapr)
map <- st_read("cb_2019_us_zcta510_500k.shp")
Reading layer `cb_2019_us_zcta510_500k' from data source `C:\Users\Donny\OneDrive\R studio\zip_codes\zip_codes\cb_2019_us_zcta510_500k.shp' using driver `ESRI Shapefile'
Simple feature collection with 33144 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -176.6847 ymin: -14.37374 xmax: 145.8304 ymax: 71.34132
Geodetic CRS: NAD83
colnames(map)[1] <- "zipcode"
map$zipcode <- as.numeric(map$zipcode)
map_ny <- map %>%
filter(zipcode > 09999 & zipcode < 15000)
ggplot(map_ny)+
geom_sf(fill = "white")
setwd("C:/Users/Donny/OneDrive/R studio")
Warning: The working directory was changed to C:/Users/Donny/OneDrive/R studio inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
data <- read.csv("select_zipcode_statistics.csv")
library(tidyr)
library(tidyverse)
Warning: package ‘tidyverse’ was built under R version 4.3.3Warning: package ‘readr’ was built under R version 4.3.3Warning: package ‘forcats’ was built under R version 4.3.3Warning: package ‘lubridate’ was built under R version 4.3.3── Attaching core tidyverse packages ────────────────────────────────────────────────────────────────────────────────── tidyverse 2.0.0 ──
✔ forcats 1.0.0 ✔ readr 2.1.5
✔ lubridate 1.9.3 ✔ stringr 1.5.1
✔ purrr 1.0.2 ✔ tibble 3.2.1── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
#join shapefile with survey data
ny1 <- map_ny %>%
left_join(data, by = c("zipcode" = "Geographic.Area.Name")) %>% drop_na() %>%
st_transform("EPSG:32116")
#get just Broome county
#load in NYS county shape file and set crs
counties <- st_read("county_basemap")
Reading layer `county' from data source `C:\Users\Donny\OneDrive\R studio\county_basemap' using driver `ESRI Shapefile'
Simple feature collection with 3142 features and 6 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -2600000 ymin: -2363000 xmax: 2516374 ymax: 732352.2
Projected CRS: +proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +ellps=sphere +units=m +no_defs
#filter the data to get just NYS
broome <- counties %>%
filter(stt_bbv == "NY") %>%
filter(cnty_nm == "Broome County") %>%
st_transform("EPSG:32116")
#isolate Broome County
broome_map <- ny1[broome,]
#plot it
ggplot(broome_map)+
geom_sf(mapping = aes(), fill = "white")+
theme_minimal()
#now let's load in the EFAM map data
setwd("C:/Users/Donny/OneDrive/R studio")
Warning: The working directory was changed to C:/Users/Donny/OneDrive/R studio inside a notebook chunk. The working directory will be reset when the chunk is finished running. Use the knitr root.dir option in the setup chunk to change the working directory for notebook chunks.
efam <- read.csv("efam_data.csv")
efam <- efam %>% filter(!Zip %in% NA )
#convert to a simple features object
efam1 <- efam %>%
#I geocoded addresses using Geocod.io
st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) %>%
st_transform(crs = st_crs(broome_map))
#plot it
#Plotting it with a look at the total population poverty just to see where people are in poverty in relation to these pantries
ggplot()+
geom_sf(data = broome_map, mapping = aes(), fill = "gray90")+
geom_sf(data = broome, mapping = aes(), color = "lightgray")+
geom_sf(data = broome_map, mapping = aes(fill = total_population_poverty), color = "green")+
scale_fill_gradient(
name = "Total Population Poverty Amount",
low = "lightblue",
high = "navyblue")+
geom_sf(data = efam1, mapping = aes(color = Type))+
theme_bw()+
labs(title = "Emergency Food Access in Broome County")
NA
NA
#From this map, we can see some very obvious deserts that need to be addressed, mainly in the areas toward the left side of the parkway, the upper right, and upper left of the county.
#First geo operation
points <- st_point_on_surface(broome_map)
Warning: st_point_on_surface assumes attributes are constant over geometries
ggplot()+
geom_sf(data = broome_map, mapping = aes(), fill = "gray90")+
geom_sf(data = points,
mapping = aes(), color = "black")+
geom_sf(data = efam1, mapping = aes(color = Type))+
theme_minimal()+
labs(title = "Emergency Food Access in Broome County and Centroids")
#Another Geospatial operation
broome_dist <- as.data.frame(st_distance(efam1, points))
#Making a new dataset to see how far a centroid is from a pantry
broome_dist <- cbind(broome_dist, efam1$Name)
colnames(broome_dist) <- c(broome_map$zipcode, "Name")
broome_dist1 <- broome_dist
broome_dist1 <- broome_dist1 %>%
separate(`13778`, c("13778", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13778` = as.numeric(`13778`))
#The actual establishment shouldnt matter here (assuming theyre all equally impactful and helpful)
#So Im dropping the "Name" column
broome_dist1 <- broome_dist1 %>% select(-c(Name))
#
broome_dist1 <- broome_dist1 %>%
separate(`13902`, c("13902", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13902` = as.numeric(`13902`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13826`, c("13826", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13826` = as.numeric(`13826`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13835`, c("13835", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13835` = as.numeric(`13835`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13730`, c("13730", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13730` = as.numeric(`13730`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13865`, c("13865", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13865` = as.numeric(`13865`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13827`, c("13827", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13827` = as.numeric(`13827`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13760`, c("13760", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13760` = as.numeric(`13760`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13790`, c("13790", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13790` = as.numeric(`13790`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13797`, c("13797", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13797` = as.numeric(`13797`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13733`, c("13733", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13733` = as.numeric(`13733`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13850`, c("13850", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13850` = as.numeric(`13850`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13863`, c("13863", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13863` = as.numeric(`13863`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13905`, c("13905", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13905` = as.numeric(`13905`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13904`, c("13904", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13904` = as.numeric(`13904`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13744`, c("13744", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13744` = as.numeric(`13744`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13804`, c("13804", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13804` = as.numeric(`13804`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13802`, c("13802", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13802` = as.numeric(`13802`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13841`, c("13841", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13841` = as.numeric(`13841`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13813`, c("13813", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13813` = as.numeric(`13813`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13754`, c("13754", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13754` = as.numeric(`13754`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13746`, c("13746", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13746` = as.numeric(`13746`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13901`, c("13901", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13901` = as.numeric(`13901`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13803`, c("13803", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13803` = as.numeric(`13803`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13903`, c("13903", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13903` = as.numeric(`13903`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13811`, c("13811", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13811` = as.numeric(`13811`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13736`, c("13736", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13736` = as.numeric(`13736`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13748`, c("13748", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13748` = as.numeric(`13748`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13862`, c("13862", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13862` = as.numeric(`13862`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13732`, c("13732", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13732` = as.numeric(`13732`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13787`, c("13787", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13787` = as.numeric(`13787`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13795`, c("13795", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13795` = as.numeric(`13795`))
#
broome_dist1 <- broome_dist1 %>%
separate(`13777`, c("13777", "county"), sep = " ") %>%
select(-county)
Warning: Expected 2 pieces. Missing pieces filled with `NA` in 175 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
broome_dist1 <- broome_dist1 %>%
mutate(`13777` = as.numeric(`13777`))
summary <- broome_dist1 %>%
summarise(`13778` = min(`13778`, na.rm = T),
`13777` = min(`13777`, na.rm = T),
`13902` = min(`13902`, na.rm = T),
`13826` = min(`13826`, na.rm = T),
`13835` = min(`13835`, na.rm = T),
`13730` = min(`13730`, na.rm = T),
`13865` = min(`13865`, na.rm = T),
`13827` = min(`13827`, na.rm = T),
`13760` = min(`13760`, na.rm = T),
`13790` = min(`13790`, na.rm = T),
`13797` = min(`13797`, na.rm = T),
`13733` = min(`13733`, na.rm = T),
`13850` = min(`13850`, na.rm = T),
`13863` = min(`13863`, na.rm = T),
`13905` = min(`13905`, na.rm = T),
`13904` = min(`13904`, na.rm = T),
`13744` = min(`13744`, na.rm = T),
`13804` = min(`13804`, na.rm = T),
`13802` = min(`13802`, na.rm = T),
`13833` = min(`13833`, na.rm = T),
`13841` = min(`13841`, na.rm = T),
`13813` = min(`13813`, na.rm = T),
`13754` = min(`13754`, na.rm = T),
`13746` = min(`13746`, na.rm = T),
`13901` = min(`13901`, na.rm = T),
`13803` = min(`13803`, na.rm = T),
`13903` = min(`13903`, na.rm = T),
`13811` = min(`13811`, na.rm = T),
`13736` = min(`13736`, na.rm = T),
`13748` = min(`13748`, na.rm = T),
`13862` = min(`13862`, na.rm = T),
`13732` = min(`13732`, na.rm = T),
`13787` = min(`13787`, na.rm = T),
`13795` = min(`13795`, na.rm = T),
)
#https://www.reddit.com/r/RStudio/comments/y53s32/working_with_columns_names_that_are_numbers_in/
#someone said use ` ` instead of ' '
#Now I need to make it long data, i tried using the way from earlier on but it didnt work for my df
long_data = data.frame(
zipcode = as.character(names(summary)),
values = unlist(summary))
#https://www.r-bloggers.com/2023/08/the-unlist-function-in-r/
#Now I need to add the column to the end of a mappable df
long_data = long_data %>% arrange(zipcode)
broome_map = broome_map %>% arrange(zipcode)
long_map <- broome_map %>% mutate(Distance = long_data$values)
#Plotting it
ggplot()+
geom_sf(data = broome_map, mapping = aes(), fill = "gray90")+
geom_sf(data = broome, mapping = aes(), color = "lightgray")+
geom_sf(data = long_map, mapping = aes(fill = Distance))+
scale_fill_gradient(
name = "Centroid Distance from nearest Emergency Food(m)",
low = "lightblue",
high = "navyblue")+
geom_sf(data = efam1, mapping = aes(color = Type))+
theme_bw()+
labs(title = "Emergency Food Access in Broome")
#Im going to look at unemployment as a number instead of a rate, looking at it as a rate would be more useful if I could put more than 1 pantry, but with 1 pantry i want to be able to help as many people as possible, and total amount unemployed is more predictive of more people having little access to buying food than unemployment rate would be
#broome_map = broome_map %>% mutate(UnemploymentRate = Unemployed/Employed) <--- this is how id calculate unemployment rate
#Poverty %
#broome_map = broome_map %>% mutate(PovertyPercent= total_population_poverty/total_population)
#New map
ggplot()+
geom_sf(data = broome_map, mapping = aes(), fill = "gray90")+
geom_sf(data = broome, mapping = aes(), color = "lightgray")+
geom_sf(data = broome_map, mapping = aes(fill = Unemployed), color = "green")+
scale_fill_gradient(
name = "Number Unemployed",
low = "lightblue",
high = "navyblue")+
geom_sf(data = efam1, mapping = aes(color = Type))+
theme_bw()+
labs(title = "Emergency Food Access in Broome County")
#https://www.sthda.com/english/wiki/ggplot2-barplots-quick-start-guide-r-software-and-data-visualization
#Plotting the top 5 zips that are farthest away
plot = long_map %>% arrange(desc(Distance))%>%head(15)
plot = plot %>% mutate(DistancesFromEmergencyFood = Distance)
plot <- plot %>% mutate(Zipcodes = as.character(zipcode))
ggplot(data=plot, aes(x=Zipcodes, y=DistancesFromEmergencyFood)) +
geom_bar(stat="identity", fill = "pink")+
labs(y = "Distances From Emergency Food (m)", x = "Zipcodes", title = "Distance from closest Emergency food spot by zipcode")+ scale_fill_manual(values = palette)
#now Im going to plot these same top zipcodes on a point graph but with unemployment and population in poverty
ggplot(plot, aes(x = total_population_poverty, y = Unemployed, color =Zipcodes )) +
geom_point() +
labs(y = "Number of Unemployed", x = "Total Number of People in Poverty", title = "Zipcodes mapped by their Numbers in Poverty and Unemployment") + scale_color_manual(values = c(`13730` = "red",`13732` = "pink",`13733` = "orange",`13736` = "black",`13744` = "darkgreen",`13746` = "lightgreen",`13778` = "slateblue",`13803` = "lightblue",`13804` = "purple",`13811` = "gold",`13813` = "brown",`13827` = "cyan",`13835` = "magenta",`13841` = "salmon",`13863` = "darkred")) + theme_minimal()
#I'm Choosing zipcode 13827 as where Id put my food pantry, heres the zipcode on a map
zippp = long_map %>% filter(Distance > 17500)
ggplot()+
geom_sf(data = broome_map, mapping = aes(), fill = "gray90")+
geom_sf(data = zippp, mapping = aes(fill = Unemployed), color = "green")+
scale_fill_gradient(
low = "lightblue",
high = "navyblue")+
geom_sf(data = efam1, mapping = aes(color = Type))+
theme_bw()+
labs(title = "Zipcode 13827")
In my analysis, I found that I’d build my new food pantry within zip code 13827, this is due to it having the absolute farthest centroids from an emergency food source along with having the absolute highest number of unemployed people and people in poverty out of the 15 zip codes with the farthest centroids.
I learned that there are a lot of zip codes within Broome County, for the longest time, I thought each county had 1 zip code, which I now realize is really dumb, but I just never looked into it and never found out I was wrong.
Working with numbers as column names was very difficult, it took me so long to realize you had to use `` instead of “” when typing column names that are also numbers, I wasted hours trying to figure out this one problem.
I think having some surrounding emergency food spots outside of broome would be needed to actually have a good idea of the spots that are farthest from food. There could be some zip codes on the border for example, that are near a food pantry, but it’s outside of Broome County so we just couldn’t see it on the map. If any data at all, I’d include these additional emergency food locations.Also, somehow not having to measure distance based on centroids would be better, maybe there was a way that I just didn’t figure out though. My zipcode has parts super close to pantrys, but the centroid is farther than all other centroids so it comes up as the farthest regardless.
Works Cited
GGPLOT2 barplots : QUICK START GUIDE - R software and Data Visualization. STHDA. (n.d.). https://www.sthda.com/english/wiki/ggplot2-barplots-quick-start-guide-r-software-and-data-visualization
II, S. P. S. (2023, August 2). The unlist() function in R: R-bloggers. R. https://www.r-bloggers.com/2023/08/the-unlist-function-in-r/
R/rstudio on reddit: Working with columns names that are numbers … (n.d.). https://www.reddit.com/r/RStudio/comments/y53s32/working_with_columns_names_that_are_numbers_in/