Task 2: Reading NYC postal areas

nyc_zipcode_sf <- st_read("Data/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `/Users/sonia/Documents/Spring 2026/R Vizualization/Module 3 - Shipeng Sun/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)

Task 3: Read and process NYS health facilities into sf objects

nys_health_facilities <- read_csv("Data/NYS_Health_Facility.csv",
                                  show_col_types=FALSE,
                                  lazy=FALSE)

# Removes missing values from coordinates
nys_health_facilities <- nys_health_facilities %>% 
  drop_na("Facility Latitude","Facility Longitude")

# Geographic Coordinates to sf object
nys_health_facilities_sf <- st_as_sf(nys_health_facilities, 
                                     coords=c("Facility Longitude","Facility Latitude"),
                                     crs=4326)

nys_health_facilities_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>, …

Task 4: Read and process NYS retail food stores into sf objects

nys_retail_food <- read_csv("Data/R-Spatial_I_Lab/nys_retail_food_store_xy.csv",show_col_types=FALSE)
names(nys_retail_food)[1] <- "County"

# Removes missing values from coordinates
nys_retail_food <- nys_retail_food %>% drop_na("X","Y")

# Geographic Coordinates to sf object
nys_retail_food_sf <- st_as_sf(nys_retail_food, coords=c("X","Y"),
                                     crs=4326)

nys_retail_food_sf
## Simple feature collection with 23972 features and 16 fields
## Geometry type: POINT
## Dimension:     XY
## Bounding box:  xmin: -79.75953 ymin: 40.50782 xmax: -71.93873 ymax: 44.99484
## Geodetic CRS:  WGS 84
## # A tibble: 23,972 × 17
##    County License.Number Operation.Type Establishment.Type Entity.Name  DBA.Name
##  * <chr>           <dbl> <chr>          <chr>              <chr>        <chr>   
##  1 Albany         733149 Store          A                  SPEEDWAY LLC 12110   
##  2 Albany         704590 Store          JAC                1250 SELKIR… 1250 SE…
##  3 Albany         727909 Store          JAC                RED-KAP SAL… 1667 GE…
##  4 Albany         720557 Store          JAC                SAEED SADIQ… 19 STRE…
##  5 Albany          15890 Store          A                  AZIZ MOHAMM… 24 HR A…
##  6 Albany         735254 Store          JAC                7-ELEVEN INC 7-ELEVEN
##  7 Albany         708848 Store          JAC                ADVANCED FR… AFC SUS…
##  8 Albany         713889 Store          JAC                ADVANCED FR… AFC SUS…
##  9 Albany         715759 Store          JAC                ADVANCED FR… AFC SUS…
## 10 Albany         723927 Store          JAC                ADVANCED FR… AFC SUS…
## # ℹ 23,962 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 [°]>

Task 5: Mapview locations

mapview(nyc_zipcode_sf)
mapview(nys_health_facilities_sf)
mapview(nys_retail_food_sf, popup=NULL)

Task 6: Save into RData File

save(nyc_zipcode_sf,nys_health_facilities_sf,nys_retail_food_sf,file ="spatial_data.RData")