Don’t use a single chunk for the entire assignment. Break it into multiple chunks.
Read in nyc zip codes in sf object
nyczip <- st_read("data/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `/Users/joelbeckwith/Documents/Hunter_College/RVizGeospatial/R-spatial/data/R-Spatial_I_Lab/ZIP_CODE_040114/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)
str(nyczip)
## Classes 'sf' and 'data.frame': 263 obs. of 13 variables:
## $ ZIPCODE : chr "11436" "11213" "11212" "11225" ...
## $ BLDGZIP : chr "0" "0" "0" "0" ...
## $ PO_NAME : chr "Jamaica" "Brooklyn" "Brooklyn" "Brooklyn" ...
## $ POPULATION: num 18681 62426 83866 56527 72280 ...
## $ AREA : num 22699295 29631004 41972104 23698630 36868799 ...
## $ STATE : chr "NY" "NY" "NY" "NY" ...
## $ COUNTY : chr "Queens" "Kings" "Kings" "Kings" ...
## $ ST_FIPS : chr "36" "36" "36" "36" ...
## $ CTY_FIPS : chr "081" "047" "047" "047" ...
## $ URL : chr "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" "http://www.usps.com/" ...
## $ SHAPE_AREA: num 0 0 0 0 0 0 0 0 0 0 ...
## $ SHAPE_LEN : num 0 0 0 0 0 0 0 0 0 0 ...
## $ geometry :sfc_POLYGON of length 263; first list element: List of 1
## ..$ : num [1:159, 1:2] 1038098 1038142 1038171 1038280 1038521 ...
## ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr [1:12] "ZIPCODE" "BLDGZIP" "PO_NAME" "POPULATION" ...
Read in NYC health facilities and make them into sf objects
nyshealth <- readr::read_csv("data/R-Spatial_I_Lab/NYS_Health_Facility.csv",
show_col_types = FALSE,
lazy = FALSE)
#str(nychealth)
nychealth_clean <- nyshealth %>%
filter(!is.na(`Facility Longitude`), !is.na(`Facility Latitude`),`Regional Office` == "Metropolitan Area Regional Office - New York City",!`Facility ID` %in% c(10383, 10324,10306))
nychealth_sf <- st_as_sf(nychealth_clean,
coords = c("Facility Longitude","Facility Latitude"),
crs = 4326)
str(nychealth_sf)
## sf [1,293 × 35] (S3: sf/tbl_df/tbl/data.frame)
## $ Facility ID : num [1:1293] 6230 7257 9006 9970 1217 ...
## $ Facility Name : chr [1:1293] "NYU Langone Rutherford" "Park Ridge Family Health Center" "FedCare, Inc." "Parkmed NYC, LLC" ...
## $ Short Description : chr [1:1293] "HOSP-EC" "HOSP-EC" "DTC" "DTC" ...
## $ Description : chr [1:1293] "Hospital Extension Clinic" "Hospital Extension Clinic" "Diagnostic and Treatment Center" "Diagnostic and Treatment Center" ...
## $ Facility Open Date : chr [1:1293] "01/01/2006" "07/08/1997" "05/14/2008" "10/31/2016" ...
## $ Facility Address 1 : chr [1:1293] "305 Second Ave" "6317 4th Avenue" "344 West 51 Street" "800 Second Avenue, 6th Floor" ...
## $ Facility Address 2 : chr [1:1293] NA NA NA NA ...
## $ Facility City : chr [1:1293] "New York" "Brooklyn" "New York" "New York" ...
## $ Facility State : chr [1:1293] "New York" "New York" "New York" "New York" ...
## $ Facility Zip Code : chr [1:1293] "10003" "11220" "10019" "10017" ...
## $ Facility Phone Number : num [1:1293] 2.13e+09 NA 2.12e+09 NA 7.19e+09 ...
## $ Facility Fax Number : num [1:1293] NA NA NA NA NA ...
## $ Facility Website : chr [1:1293] NA NA NA NA ...
## $ Facility County Code : num [1:1293] 7093 7095 7093 7093 7094 ...
## $ Facility County : chr [1:1293] "New York" "Kings" "New York" "New York" ...
## $ Regional Office ID : num [1:1293] 5 5 5 5 5 5 5 5 5 5 ...
## $ Regional Office : chr [1:1293] "Metropolitan Area Regional Office - New York City" "Metropolitan Area Regional Office - New York City" "Metropolitan Area Regional Office - New York City" "Metropolitan Area Regional Office - New York City" ...
## $ Main Site Name : chr [1:1293] "NYU Langone Hospitals" "NYU Langone Hospitals" NA NA ...
## $ Main Site Facility ID : num [1:1293] 1463 1463 NA NA NA ...
## $ Operating Certificate Number: chr [1:1293] "7002053H" "7002053H" "7002813R" "7002807R" ...
## $ Operator Name : chr [1:1293] "NYU Langone Hospitals" "NYU Langone Hospitals" "FedCare, Inc." "Parkmed NYC, LLC" ...
## $ Operator Address 1 : chr [1:1293] "550 First Avenue" "550 First Avenue" "344 West 51st Street" "800 Second Avenue" ...
## $ Operator Address 2 : chr [1:1293] NA NA NA "8th Floor" ...
## $ Operator City : chr [1:1293] "New York" "New York" "New York" "New York" ...
## $ Operator State : chr [1:1293] "New York" "New York" "New York" "New York" ...
## $ Operator Zip Code : chr [1:1293] "10016" "10016" "10019" "10017" ...
## $ Cooperator Name : chr [1:1293] NA NA NA NA ...
## $ Cooperator Address : chr [1:1293] NA NA NA NA ...
## $ Cooperator Address 2 : chr [1:1293] NA NA NA NA ...
## $ Cooperator City : chr [1:1293] NA NA NA NA ...
## $ Cooperator State : chr [1:1293] "New York" "New York" "New York" "New York" ...
## $ Cooperator Zip Code : chr [1:1293] NA NA NA NA ...
## $ Ownership Type : chr [1:1293] "Not for Profit Corporation" "Not for Profit Corporation" "Not for Profit Corporation" "LLC" ...
## $ Facility Location : chr [1:1293] "(40.734818, -73.983231)" "(40.638981, -74.020172)" "(40.76363, -73.98748)" "(40.750033, -73.971612)" ...
## $ geometry :sfc_POINT of length 1293; first list element: 'XY' num [1:2] -74 40.7
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr [1:34] "Facility ID" "Facility Name" "Short Description" "Description" ...
Read in NYC retail food service data and convert to sf objects
nysretfd <- readr::read_csv("data/R-Spatial_I_Lab/nys_retail_food_store_xy.csv",
show_col_types= FALSE,
lazy= FALSE,
locale = readr::locale(encoding = "latin1"))
#str(nysretfd)
nycretfd_clean = nysretfd %>%
filter(`ï..County` %in% c("Richmond","Kings","Queens","Bronx","New York"),
!is.na(`X`), !is.na(`Y`))
#str(nycretfd_clean)
nycretfd_sf <- st_as_sf(nycretfd_clean,
coords = c("X","Y"),
crs = 4326)
Map each of the data points
nychealth_sf %>% mapview::mapview(basemaps = c("Esri.WorldImagery"))
nycretfd_sf %>% mapview::mapview(basemaps = c("Esri.WorldImagery"))