Packages

require(tidyverse);
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
require(sf); 
## Loading required package: sf
## Linking to GEOS 3.11.2, GDAL 3.8.2, PROJ 9.3.1; sf_use_s2() is TRUE
require(mapview); 
## Loading required package: mapview
require(magrittr); 
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## The following object is masked from 'package:tidyr':
## 
##     extract

R Spaital Lab Assignment # 1

Don’t use a single chunk for the entire assignment. Break it into multiple chunks.

Reading Data:

Reading in the data and filtering for NAs and counties

library(tidyverse)
nyc_pa<-st_read('ZIP_CODE_040114/ZIP_CODE_040114.shp')
## Reading layer `ZIP_CODE_040114' from data source 
##   `C:\Users\OWNER\Downloads\intro to r class\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)
nys_hf<-read.csv('NYS_Health_Facility.csv')
nys_hf_clean<-nys_hf %>%
  filter(complete.cases(Facility.Longitude, Facility.Latitude))

nys_rfsxy<-read.csv('nys_retail_food_store_xy.csv')
nys_rfsxy_clean<- nys_rfsxy %>%
  filter(complete.cases(Y, X)) %>%
  filter(County %in% c("New York","Richmond","Kings","Bronx","Queens"))

Converting to Spatial

nys_hf_sf<-st_as_sf(nys_hf_clean, coords=c('Facility.Longitude','Facility.Latitude'))
nys_rfs_sf<-st_as_sf(nys_rfsxy_clean, coords=c('X','Y'))

EPSGs

Checking and adding EPSGs in order to map data.

st_crs(nyc_pa)
## Coordinate Reference System:
##   User input: NAD83 / New York Long Island (ftUS) 
##   wkt:
## PROJCRS["NAD83 / New York Long Island (ftUS)",
##     BASEGEOGCRS["NAD83",
##         DATUM["North American Datum 1983",
##             ELLIPSOID["GRS 1980",6378137,298.257222101,
##                 LENGTHUNIT["metre",1]]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4269]],
##     CONVERSION["SPCS83 New York Long Island zone (US survey foot)",
##         METHOD["Lambert Conic Conformal (2SP)",
##             ID["EPSG",9802]],
##         PARAMETER["Latitude of false origin",40.1666666666667,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8821]],
##         PARAMETER["Longitude of false origin",-74,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8822]],
##         PARAMETER["Latitude of 1st standard parallel",41.0333333333333,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8823]],
##         PARAMETER["Latitude of 2nd standard parallel",40.6666666666667,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8824]],
##         PARAMETER["Easting at false origin",984250,
##             LENGTHUNIT["US survey foot",0.304800609601219],
##             ID["EPSG",8826]],
##         PARAMETER["Northing at false origin",0,
##             LENGTHUNIT["US survey foot",0.304800609601219],
##             ID["EPSG",8827]]],
##     CS[Cartesian,2],
##         AXIS["easting (X)",east,
##             ORDER[1],
##             LENGTHUNIT["US survey foot",0.304800609601219]],
##         AXIS["northing (Y)",north,
##             ORDER[2],
##             LENGTHUNIT["US survey foot",0.304800609601219]],
##     USAGE[
##         SCOPE["Engineering survey, topographic mapping."],
##         AREA["United States (USA) - New York - counties of Bronx; Kings; Nassau; New York; Queens; Richmond; Suffolk."],
##         BBOX[40.47,-74.26,41.3,-71.8]],
##     ID["EPSG",2263]]
st_crs(nys_hf_sf)<-4326
st_crs(nys_rfs_sf)<-4326
nyc_pa_wg84<-st_transform(nyc_pa,4326)

Mapping

Dataset 1: Zip codes

mapview(nyc_pa_wg84,map.types='OpenStreetMap')

Dataset 2: Health Facilities

mapview(nys_hf_sf,map.types='OpenStreetMap')

Dataset 3: Retail Food Stores

mapview(nys_rfs_sf, map.types = "OpenStreetMap")