Explanation of the template

Hi, my name is Kamilly, but I also go by “Kami”. I am a rising senior majoring in environmental studies. One interesting fact about me is that i have a pet cat and a pet bird. I am interested in plants and nature and i enjoy going to the park.

R Spatial Lab Assignment # 1

Task 1:Join the COVID-19 data to the NYC zip code area data

covid_data<- read.csv("R-Spatial_II_Lab/R-Spatial_II_Lab/tests-by-zcta_2021_04_23.csv")
covid_sf<- st_as_sf(covid_data, coords=c("lon","lat"), crs=4326)


nyc_zipcode<-st_read("R-Spatial_I_Lab/ZIP_CODE_040114/ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source 
##   `C:\Users\Kami\Downloads\Section_08\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)
zipcode_sf<-st_transform(nyc_zipcode,4326)


zipcode_merge<- st_join(zipcode_sf,covid_sf)
head(zipcode_merge)
## Simple feature collection with 6 features and 23 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -73.99193 ymin: 40.63029 xmax: -73.78805 ymax: 40.6863
## Geodetic CRS:  WGS 84
##   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
##                    URL SHAPE_AREA SHAPE_LEN MODIFIED_ZCTA
## 1 http://www.usps.com/          0         0         11436
## 2 http://www.usps.com/          0         0         11213
## 3 http://www.usps.com/          0         0         11212
## 4 http://www.usps.com/          0         0         11225
## 5 http://www.usps.com/          0         0         11218
## 6 http://www.usps.com/          0         0         11226
##                                NEIGHBORHOOD_NAME BOROUGH_GROUP label
## 1                 South Jamaica/South Ozone Park        Queens 11436
## 2                           Crown Heights (East)      Brooklyn 11213
## 3                         Ocean Hill-Brownsville      Brooklyn 11212
## 4 Crown Heights (West)/Prospect Lefferts Gardens      Brooklyn 11225
## 5                     Kensington/Windsor Terrace      Brooklyn 11218
## 6             Flatbush/Prospect Lefferts Gardens      Brooklyn 11226
##   COVID_CASE_COUNT COVID_CASE_RATE POP_DENOMINATOR COVID_DEATH_COUNT
## 1             1888         9419.96        20042.54                64
## 2             5166         7996.75        64601.26               203
## 3             7182         9709.74        73966.99               330
## 4             3833         6664.50        57513.69               177
## 5             6199         8377.49        73995.92               218
## 6             7279         7476.75        97355.08               368
##   COVID_DEATH_RATE PERCENT_POSITIVE TOTAL_COVID_TESTS
## 1           319.32            17.57             11082
## 2           314.24            13.72             38560
## 3           446.14            15.64             47319
## 4           307.75            11.62             33709
## 5           294.61            13.93             45884
## 6           378.00            13.33             56287
##                         geometry
## 1 POLYGON ((-73.80585 40.6829...
## 2 POLYGON ((-73.9374 40.67973...
## 3 POLYGON ((-73.90294 40.6708...
## 4 POLYGON ((-73.95797 40.6706...
## 5 POLYGON ((-73.97208 40.6506...
## 6 POLYGON ((-73.9619 40.65487...
plot(zipcode_merge["COVID_CASE_COUNT"])

Task 2:

nyc_foods<-st_read("R-Spatial_II_Lab/R-Spatial_II_Lab/nycFoodStore.shp")
## Reading layer `nycFoodStore' from data source 
##   `C:\Users\Kami\Downloads\Section_08\R-Spatial_II_Lab\R-Spatial_II_Lab\nycFoodStore.shp' 
##   using driver `ESRI Shapefile'
## 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
zipcode_foods<-zipcode_merge %>%
  st_join(nyc_foods) %>%
  group_by(geometry)%>%
  mutate(n_food_stores=n())

plot(zipcode_foods["n_food_stores"])

Task 3:

nychealth<-read_csv("R-Spatial_I_Lab/NYS_Health_Facility.csv")
## Rows: 3985 Columns: 36
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (27): Facility Name, Short Description, Description, Facility Open Date,...
## dbl  (9): Facility ID, Facility Phone Number, Facility Fax Number, Facility ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
missing_long <- is.na(nychealth$`Facility Longitude`)
missing_lat <- is.na(nychealth$`Facility Latitude`)


missing_coords <- missing_long | missing_lat


nychealth_clean <- nychealth[!missing_coords, ]

nychealthsf <- st_as_sf(nychealth_clean, coords = c("Facility Longitude", "Facility Latitude"), crs = 4326)



zipcode_health<-zipcode_foods %>%
  st_join(nychealthsf) %>%
  group_by(geometry)%>%
  mutate(n_health_fac=n())

zipcode_health<-zipcode_health %>%
  filter(Description == "Hospital") %>%
  group_by(geometry)%>%
  mutate(n_hospital_fac=n())

zipcode_health <- zipcode_health %>%
  rename("Number of Hospitals" = "n_hospital_fac")


plot(zipcode_health["Number of Hospitals"])

Task 4:

census_tract<-st_read("R-Spatial_II_Lab/R-Spatial_II_Lab/2010 Census Tracts/geo_export_1dc7b645-647b-4806-b9a0-7b79660f120a.shp")
## Reading layer `geo_export_1dc7b645-647b-4806-b9a0-7b79660f120a' from data source `C:\Users\Kami\Downloads\Section_08\R-Spatial_II_Lab\R-Spatial_II_Lab\2010 Census Tracts\geo_export_1dc7b645-647b-4806-b9a0-7b79660f120a.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 2165 features and 11 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -74.25559 ymin: 40.49612 xmax: -73.70001 ymax: 40.91553
## Geodetic CRS:  WGS84(DD)
ACS_data<-read_csv("R-Spatial_II_Lab/R-Spatial_II_Lab/ACSDP5Y2018.DP05_data_with_overlays_2020-04-22T132935.csv")
## Rows: 2167 Columns: 358
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (181): GEO_ID, NAME, DP05_0031PM, DP05_0032E, DP05_0032M, DP05_0032PE, D...
## dbl (177): Totalpop, DP05_0033M, DP05_0033PE, DP05_0034E, DP05_0034M, DP05_0...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
c_tract<-census_tract %<>% dplyr::mutate(cntyFIPS = case_when(
  boro_name == 'Bronx' ~ '005',
  boro_name == 'Brooklyn' ~ '047',
  boro_name == 'Manhattan' ~ '061',
  boro_name == 'Queens' ~ '081',
  boro_name == 'Staten Island' ~ '085'),
  tractFIPS = paste(cntyFIPS, ct2010, sep='')
)

acsData <- ACS_data %>%
  dplyr::select(GEO_ID,
                 totPop = DP05_0001E,
                 elderlyPop = DP05_0024E, # >= 65
                 malePop = DP05_0002E,
                 femalePop = DP05_0003E,
                 whitePop = DP05_0037E,
                 blackPop = DP05_0038E,
                 asianPop = DP05_0067E,
                 hispanicPop = DP05_0071E,
                 adultPop = DP05_0021E,
                 citizenAdult = DP05_0087E) %>%
  mutate(censusCode = str_sub(GEO_ID, -9, -1))

acsData %>%
  magrittr::extract(1:10,)
## # A tibble: 10 × 12
##    GEO_ID         totPop elderlyPop malePop femalePop whitePop blackPop asianPop
##    <chr>           <dbl>      <dbl>   <dbl>     <dbl>    <dbl>    <dbl>    <dbl>
##  1 1400000US3600…   7080         51    6503       577     1773     4239      130
##  2 1400000US3600…   4542        950    2264      2278     2165     1279      119
##  3 1400000US3600…   5634        710    2807      2827     2623     1699      226
##  4 1400000US3600…   5917        989    2365      3552     2406     2434       68
##  5 1400000US3600…   2765         76    1363      1402      585     1041      130
##  6 1400000US3600…   9409        977    4119      5290     3185     4487       29
##  7 1400000US3600…   4600        648    2175      2425      479     2122       27
##  8 1400000US3600…    172          0     121        51       69       89       14
##  9 1400000US3600…   5887        548    2958      2929      903     1344       68
## 10 1400000US3600…   2868        243    1259      1609      243      987        0
## # ℹ 4 more variables: hispanicPop <dbl>, adultPop <dbl>, citizenAdult <dbl>,
## #   censusCode <chr>
popData <- merge(c_tract, acsData, by.x ='tractFIPS', by.y = 'censusCode')



plot(popData["blackPop"])

Task 5:

popData5<-st_transform(popData, 4326)


ACS_zip <- zipcode_sf %>%
  st_join(popData5) %>%
  group_by(ZIPCODE)
  
plot(ACS_zip["totPop"])