zip_sf <- st_read("../ZIP_CODE/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `/Users/uwu/Documents/RSpatial/Week7/ZIP_CODE/ZIP_CODE_040114.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 263 features and 12 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 913129 ymin: 120020.9 xmax: 1067494 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
zip_sf
## Simple feature collection with 263 features and 12 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 913129 ymin: 120020.9 xmax: 1067494 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
## First 10 features:
## ZIPCODE BLDGZIP PO_NAME POPULATION AREA STATE COUNTY ST_FIPS CTY_FIPS
## 1 11436 0 Jamaica 18681 22699295 NY Queens 36 081
## 2 11213 0 Brooklyn 62426 29631004 NY Kings 36 047
## 3 11212 0 Brooklyn 83866 41972104 NY Kings 36 047
## 4 11225 0 Brooklyn 56527 23698630 NY Kings 36 047
## 5 11218 0 Brooklyn 72280 36868799 NY Kings 36 047
## 6 11226 0 Brooklyn 106132 39408598 NY Kings 36 047
## 7 11219 0 Brooklyn 92561 42002738 NY Kings 36 047
## 8 11210 0 Brooklyn 67067 47887023 NY Kings 36 047
## 9 11230 0 Brooklyn 80857 49926703 NY Kings 36 047
## 10 11204 0 Brooklyn 77354 43555185 NY Kings 36 047
## URL SHAPE_AREA SHAPE_LEN geometry
## 1 http://www.usps.com/ 0 0 POLYGON ((1038098 188138.4,...
## 2 http://www.usps.com/ 0 0 POLYGON ((1001614 186926.4,...
## 3 http://www.usps.com/ 0 0 POLYGON ((1011174 183696.3,...
## 4 http://www.usps.com/ 0 0 POLYGON ((995908.4 183617.6...
## 5 http://www.usps.com/ 0 0 POLYGON ((991997.1 176307.5...
## 6 http://www.usps.com/ 0 0 POLYGON ((994821.5 177865.7...
## 7 http://www.usps.com/ 0 0 POLYGON ((987286.4 173946.5...
## 8 http://www.usps.com/ 0 0 POLYGON ((995796 171110.1, ...
## 9 http://www.usps.com/ 0 0 POLYGON ((994099.3 171240.7...
## 10 http://www.usps.com/ 0 0 POLYGON ((989500.2 170730.2...
plot(st_geometry(zip_sf), col = "lightblue", border = "gray")
The health facility data was converted into a spatial object using longitude and latitude coordinates. Missing and invalid coordinate values were removed and the data was filtered to include only facilities within the New York region. The resulting spatial points were mapped alongside ZIP code polygons to verify their geographic alignment.
health <- read_csv("../R-Spatial_Lab/NYS_Health_Facility.csv")
health2 <- health %>%
filter(!is.na('Facility Longitude'), !is.na('Facility Latitude'))
names(health)
## [1] "Facility ID" "Facility Name"
## [3] "Short Description" "Description"
## [5] "Facility Open Date" "Facility Address 1"
## [7] "Facility Address 2" "Facility City"
## [9] "Facility State" "Facility Zip Code"
## [11] "Facility Phone Number" "Facility Fax Number"
## [13] "Facility Website" "Facility County Code"
## [15] "Facility County" "Regional Office ID"
## [17] "Regional Office" "Main Site Name"
## [19] "Main Site Facility ID" "Operating Certificate Number"
## [21] "Operator Name" "Operator Address 1"
## [23] "Operator Address 2" "Operator City"
## [25] "Operator State" "Operator Zip Code"
## [27] "Cooperator Name" "Cooperator Address"
## [29] "Cooperator Address 2" "Cooperator City"
## [31] "Cooperator State" "Cooperator Zip Code"
## [33] "Ownership Type" "Facility Latitude"
## [35] "Facility Longitude" "Facility Location"
health2 <- health %>%
mutate(
`Facility Longitude` = as.numeric(`Facility Longitude`),
`Facility Latitude` = as.numeric(`Facility Latitude`)
) %>%
filter(
!is.na(`Facility Longitude`) &
!is.na(`Facility Latitude`)
)
health_ny <- health2 %>%
filter(`Facility County` %in% c("Bronx", "Kings", "New York", "Queens", "Richmond"))
health_sf <- st_as_sf(
health2,
coords = c("Facility Longitude", "Facility Latitude"),
crs = 4326
)
health_sf
## Simple feature collection with 3848 features and 34 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -79.6299 ymin: -75.45935 xmax: 43.21162 ymax: 44.97849
## Geodetic CRS: WGS 84
## # A tibble: 3,848 × 35
## `Facility ID` `Facility Name` `Short Description` Description
## * <dbl> <chr> <chr> <chr>
## 1 204 Hospice at Lourdes HSPC Hospice
## 2 620 Charles T Sitrin Health Care C… NH Residentia…
## 3 1156 East Side Nursing Home NH Residentia…
## 4 2589 Wellsville Manor Care Center NH Residentia…
## 5 3455 Harris Hill Nursing Facility, … NH Residentia…
## 6 3853 Garden City Surgi Center DTC Diagnostic…
## 7 4249 Willcare CHHA Certified …
## 8 4473 Good Shepherd Hospice HSPC Hospice
## 9 6230 NYU Langone Rutherford HOSP-EC Hospital E…
## 10 6482 Endoscopy Center of Long Islan… DTC Diagnostic…
## # ℹ 3,838 more rows
## # ℹ 31 more variables: `Facility Open Date` <chr>, `Facility Address 1` <chr>,
## # `Facility Address 2` <chr>, `Facility City` <chr>, `Facility State` <chr>,
## # `Facility Zip Code` <chr>, `Facility Phone Number` <dbl>,
## # `Facility Fax Number` <dbl>, `Facility Website` <chr>,
## # `Facility County Code` <dbl>, `Facility County` <chr>,
## # `Regional Office ID` <dbl>, `Regional Office` <chr>, …
summary(health2$`Facility Longitude`)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -79.63 -75.91 -73.96 -74.77 -73.84 43.21
summary(health2$`Facility Latitude`)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -75.46 40.77 41.37 41.75 42.92 44.98
health2 %>%
filter(`Facility Longitude` > -70 |
`Facility Longitude` < -80 |
`Facility Latitude` < 40 |
`Facility Latitude` > 46
)
## # A tibble: 5 × 36
## `Facility ID` `Facility Name` `Short Description` Description
## <dbl> <chr> <chr> <chr>
## 1 5764 Alcohol Outpatient Clinic HOSP-EC Hospital E…
## 2 10337 HRHCare Kingston DTC-EC Diagnostic…
## 3 10306 Queens Boulevard Extended Care … DTC Diagnostic…
## 4 10324 Union Square Eye Care - Harlem DTC Diagnostic…
## 5 10383 Stuyvesant Heights Dialysis DTC-EC Diagnostic…
## # ℹ 32 more variables: `Facility Open Date` <chr>, `Facility Address 1` <chr>,
## # `Facility Address 2` <chr>, `Facility City` <chr>, `Facility State` <chr>,
## # `Facility Zip Code` <chr>, `Facility Phone Number` <dbl>,
## # `Facility Fax Number` <dbl>, `Facility Website` <chr>,
## # `Facility County Code` <dbl>, `Facility County` <chr>,
## # `Regional Office ID` <dbl>, `Regional Office` <chr>,
## # `Main Site Name` <chr>, `Main Site Facility ID` <dbl>, …
health_sf <- st_as_sf(
health_ny,
coords = c("Facility Longitude", "Facility Latitude"),
crs = 4326
)
nys_retail_food_df <- read_csv("../R-Spatial_Lab/nys_retail_food_store_xy.csv",
show_col_types = FALSE
)
names(nys_retail_food_df)[1] <- "County"
names(nys_retail_food_df)
## [1] "County" "License.Number" "Operation.Type"
## [4] "Establishment.Type" "Entity.Name" "DBA.Name"
## [7] "Street.Number" "Street.Name" "Address.Line.2"
## [10] "Address.Line.3" "City" "State"
## [13] "Zip.Code" "Square.Footage" "Location"
## [16] "Coords" "Y" "X"
unique(nys_retail_food_df$County)
## [1] "Albany" "Allegany" "Bronx" "Broome" "Cattaraugus"
## [6] "Cayuga" "Chautauqua" "Chemung" "Chenango" "Clinton"
## [11] "Columbia" "Cortland" "Delaware" "Dutchess" "Erie"
## [16] "Essex" "Franklin" "Fulton" "Genesee" "Greene"
## [21] "Hamilton" "Herkimer" "Jefferson" "Kings" "Lewis"
## [26] "Livingston" "Madison" "Monroe" "Montgomery" "Nassau"
## [31] "New York" "Niagara" "Oneida" "Onondaga" "Ontario"
## [36] "Orange" "Orleans" "Oswego" "Otsego" "Putnam"
## [41] "Queens" "Rensselaer" "Richmond" "Rockland" "Saratoga"
## [46] "Schenectady" "Schoharie" "Schuyler" "Seneca" "Steuben"
## [51] "St. Lawrence" "Suffolk" "Sullivan" "Tioga" "Tompkins"
## [56] "Ulster" "Warren" "Washington" "Wayne" "Westchester"
## [61] "Wyoming" "Yates"
nyc_retail_food_df <- nys_retail_food_df %>% filter(County %in%
c("Bronx", "Kings", "New York", "Queens", "Richmond")) %>%
filter(!is.na(X) & !is.na(Y))
nyc_retail_sf <- st_as_sf(
nyc_retail_food_df,
coords = c("X", "Y")
, crs = 4326
)
nyc_retail_sf
## Simple feature collection with 11300 features and 16 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -74.2484 ymin: 40.50782 xmax: -73.67061 ymax: 40.91008
## Geodetic CRS: WGS 84
## # A tibble: 11,300 × 17
## County License.Number Operation.Type Establishment.Type Entity.Name DBA.Name
## * <chr> <dbl> <chr> <chr> <chr> <chr>
## 1 Bronx 734149 Store JAC 7 ELEVEN FO… <NA>
## 2 Bronx 606221 Store JAC 1001 SAN MI… 1001 SA…
## 3 Bronx 606228 Store JAC 1029 FOOD P… 1029 FO…
## 4 Bronx 723375 Store JAC 1078 DELI G… 1078 DE…
## 5 Bronx 724807 Store JAC 1086 LUNA D… 1086 LU…
## 6 Bronx 712943 Store JAC 109 AJ DELI… 109 AJ …
## 7 Bronx 703060 Store JAC 10 NEIGHBOR… 10 NEIG…
## 8 Bronx 609065 Store JAC 1105 TINTON… 1105 TI…
## 9 Bronx 722972 Store A 1150 WEBSTE… 1150 WE…
## 10 Bronx 609621 Store JAC 1158 GROCER… 1158 GR…
## # ℹ 11,290 more rows
## # ℹ 11 more variables: Street.Number <chr>, Street.Name <chr>,
## # Address.Line.2 <lgl>, Address.Line.3 <lgl>, City <chr>, State <chr>,
## # Zip.Code <dbl>, Square.Footage <dbl>, Location <chr>, Coords <chr>,
## # geometry <POINT [°]>
save(zip_sf, health_sf, nyc_retail_sf, file = "lab1_spatial_objects.RData")
st_write(zip_sf, "lab1_data.gpkg", layer = "zip_sf", delete_layer = TRUE)
## Deleting layer `zip_sf' using driver `GPKG'
## Writing layer `zip_sf' to data source `lab1_data.gpkg' using driver `GPKG'
## Writing 263 features with 12 fields and geometry type Polygon.
st_write(health_sf, "lab1_data.gpkg", layer = "health_sf", delete_layer = TRUE)
## Deleting layer `health_sf' using driver `GPKG'
## Writing layer `health_sf' to data source `lab1_data.gpkg' using driver `GPKG'
## Writing 1295 features with 34 fields and geometry type Point.
st_write(nyc_retail_sf, "lab1_data.gpkg", layer = "nyc_retail_sf", delete_layer = TRUE)
## Deleting layer `nyc_retail_sf' using driver `GPKG'
## Writing layer `nyc_retail_sf' to data source `lab1_data.gpkg' using driver `GPKG'
## Writing 11300 features with 16 fields and geometry type Point.
The first map shows that both health facilities and retail food stores are clustered in central areas of NYC, especially in Manhattan and parts of Brooklyn. There is a noticeable overlap between the two suggesting that areas with more development have greater access to services. Outer areas tend to have fewer points indicating lower service availability.
The second map of health facilities are spread across NYC but some ZIP codes have noticeably higher counts than others. There appears to be a moderate concentration in certain parts of Manhattan and the Bronx. Overall, the distribution is uneven, indicating that access to healthcare services may differ by location.
The final map of the distribution of retail food stores varies across NYC with higher concentrations in parts of Manhattan and Brooklyn. Some ZIP codes show significantly more stores than others while areas like Staten Island have fewer. This suggests that access to food stores is uneven and may be related to population density.
health_sf_proj <- st_transform(health_sf, st_crs(zip_sf))
nyc_retail_sf_proj <- st_transform(nyc_retail_sf, st_crs(zip_sf))
plot(st_geometry(zip_sf), col = "gray", border = "white")
plot(st_geometry(health_sf_proj), add = TRUE, col = "red", pch = 16)
plot(st_geometry(nyc_retail_sf_proj), add = TRUE, col = "blue", pch = 16)
zip_health <- st_join(zip_sf, health_sf_proj) %>%
group_by(ZIPCODE) %>%
summarize(health_count = n())
zip_retail <- st_join(zip_sf, nyc_retail_sf_proj) %>%
group_by(ZIPCODE) %>%
summarize(retail_count = n())
plot(zip_health["health_count"],
main = "Health Facilities per Zip",
pal = hcl.colors)
plot(zip_retail["retail_count"],
main = "Retail Food Stores per ZIP",
pal = hcl.colors)