R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Step 1

library(sf)
## Warning: package 'sf' was built under R version 4.3.3
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(mapview)
## Warning: package 'mapview' was built under R version 4.3.3
library(readr)
## Warning: package 'readr' was built under R version 4.3.1
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.3.3
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
##   Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
##   OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## 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

Step 2

wd <- getwd()
nyc_sf <- st_read("Session_7/R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `C:\Users\naial\OneDrive\Documents\Geog393\Section 3\Session_7\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)

Step 3

health_fac <- read_csv("Session_7/R-Spatial_I_Lab/NYS_Health_Facility.csv", 
                               show_col_types = FALSE, 
                               lazy = FALSE) 


health_fac <- health_fac[!is.na(health_fac$`Facility Latitude`) & !is.na(health_fac$`Facility Longitude`),]

health_fac_sf <- st_as_sf(health_fac, 
                               coords = c("Facility Longitude", "Facility Latitude"))

Step 4

retail_food <- read_csv("Session_7/R-Spatial_I_Lab/nys_retail_food_store_xy.csv", 
                               show_col_types = FALSE, 
                               lazy = FALSE) 


retail_food <- retail_food[!is.na(retail_food$`Y`) & !is.na(retail_food$`X`),]

retail_food <- retail_food %>% 
  filter(County %in% c("Bronx", "Kings", "New York", "Queens", "Richmond"))

retail_food_sf <- st_as_sf(retail_food, 
                               coords = c("X", "Y"))

Step 5

mapview(nyc_sf, layer.name='NYCZip')
mapview(health_fac_sf, layer.name='HealthFac')
mapview(retail_food_sf, layer.name='RetailFood')

Step 6

save(nyc_sf, health_fac_sf, retail_food_sf, file = "Session_7/R-Spatial_I_Lab/Session7HWNaiaL")