Update the title with your information. Make sure to include identification information so that we know it is your submission.
Also update the author name and date accordingly.
Check out the Source Code from the top-right corner
</>Code
menu.
In the following R code chunk, load_packages
is the code
chunk name. include=FALSE
suggests that the code chunk will
run, but the code itself and its outputs will not be included in the
rendered HTML. echo=TRUE
in the following code chunk
suggests that the code and results from running the code will be
included in the rendered HTML.
Don’t use a single chunk for the entire assignment. Break it into multiple chunks.
smpCode <- "hello, R markdown and RPubs!"
cat(smpCode)
## hello, R markdown and RPubs!
Quarto markdown is different from R markdown in terms of chunk options. See chunk options at Quarto website.
print("This is the new code chunk options available in Quarto Markdown")
## [1] "This is the new code chunk options available in Quarto Markdown"
# Load data
ZipCodessf <- st_read("C:\\Users\\zim13\\Downloads\\Section_07\\Data\\R-Spatial_I_Lab\\ZIP_CODE_040114\\ZIP_CODE_040114.shp")
## Reading layer `ZIP_CODE_040114' from data source
## `C:\Users\zim13\Downloads\Section_07\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)
FoodStoressf <- st_read('C:\\Users\\zim13\\Downloads\\Section_07\\Section_08\\R-Spatial_II_Lab\\R-Spatial_II_Lab\\nycFoodStore.shp')
## Reading layer `nycFoodStore' from data source
## `C:\Users\zim13\Downloads\Section_07\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
CensusNYC <- st_read("C:\\Users\\zim13\\Downloads\\Section_07\\Section_08\\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\zim13\Downloads\Section_07\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)
HealthFacilitiesCsv <- read.csv("C:\\Users\\zim13\\Downloads\\Section_07\\Section_08\\R-Spatial_II_Lab\\R-Spatial_II_Lab\\NYS_Health_Facility.csv")
HealthFacilitiesCsv <- HealthFacilitiesCsv %>% filter(between(Facility.Longitude, -79.8, -71.8) & between(Facility.Latitude, 40.0, 45.5))
HealthFacilitiesSF <- st_as_sf(HealthFacilitiesCsv, coords = c("Facility.Longitude", "Facility.Latitude"), crs = 2263)
CovidData <- read.csv("C:\\Users\\zim13\\Downloads\\Section_07\\Section_08\\R-Spatial_II_Lab\\R-Spatial_II_Lab\\tests-by-zcta_2021_04_23.csv")
CovidClean <- CovidData %>% dplyr::select(MODIFIED_ZCTA, COVID_CASE_COUNT, COVID_CASE_RATE, PERCENT_POSITIVE, TOTAL_COVID_TESTS) %>% group_by(MODIFIED_ZCTA) %>% summarize(COVID_CASE_COUNT = sum(COVID_CASE_COUNT, na.rm = TRUE), COVID_CASE_RATE = mean(COVID_CASE_RATE, na.rm = TRUE), PERCENT_POSITIVE = mean(PERCENT_POSITIVE, na.rm = TRUE), TOTAL_COVID_TESTS = sum(TOTAL_COVID_TESTS, na.rm = TRUE))
ACS <- read.csv("C:\\Users\\zim13\\Downloads\\Section_07\\Section_08\\R-Spatial_II_Lab\\R-Spatial_II_Lab\\ACSDP5Y2018.DP05_data_with_overlays_2020-04-22T132935.csv")
# Have both be characters so we can join them
CovidData$MODIFIED_ZCTA <- as.character(CovidData$MODIFIED_ZCTA)
# Left join by zipcode since its conssitent across both
ZipCodessf <- ZipCodessf %>%
left_join(CovidData, by = c("ZIPCODE" = "MODIFIED_ZCTA"))
colnames(ZipCodessf)
## [1] "ZIPCODE" "BLDGZIP" "PO_NAME"
## [4] "POPULATION" "AREA" "STATE"
## [7] "COUNTY" "ST_FIPS" "CTY_FIPS"
## [10] "URL" "SHAPE_AREA" "SHAPE_LEN"
## [13] "NEIGHBORHOOD_NAME" "BOROUGH_GROUP" "label"
## [16] "lat" "lon" "COVID_CASE_COUNT"
## [19] "COVID_CASE_RATE" "POP_DENOMINATOR" "COVID_DEATH_COUNT"
## [22] "COVID_DEATH_RATE" "PERCENT_POSITIVE" "TOTAL_COVID_TESTS"
## [25] "geometry"
# Filter
FSfiltered <- FoodStoressf %>%
filter(Oprtn_T == "Store")
#Double Check
colnames(FoodStoressf)
## [1] "ï__Cnty" "Lcns_Nm" "Oprtn_T" "Estbl_T" "Entty_N" "DBA_Nam"
## [7] "Strt_Nmb" "Stret_Nm" "Add_L_2" "Add_L_3" "City" "State"
## [13] "Zip_Cod" "Sqr_Ftg" "Locatin" "Coords" "geometry"
# Group zip codes
FSZip <- FoodStoressf %>% st_drop_geometry() %>% group_by(Zip_Cod) %>% summarize(store_count = n())
# Turn to character to join
FSZip <- FSZip %>% mutate(Zip_Cod = as.character(Zip_Cod))
CovidClean <- CovidClean %>% mutate(MODIFIED_ZCTA = as.character(MODIFIED_ZCTA))
ZipCovidsf <- ZipCodessf %>% left_join(CovidClean, by = c("ZIPCODE" = "MODIFIED_ZCTA"))
colnames(ZipCovidsf)
## [1] "ZIPCODE" "BLDGZIP" "PO_NAME"
## [4] "POPULATION" "AREA" "STATE"
## [7] "COUNTY" "ST_FIPS" "CTY_FIPS"
## [10] "URL" "SHAPE_AREA" "SHAPE_LEN"
## [13] "NEIGHBORHOOD_NAME" "BOROUGH_GROUP" "label"
## [16] "lat" "lon" "COVID_CASE_COUNT.x"
## [19] "COVID_CASE_RATE.x" "POP_DENOMINATOR" "COVID_DEATH_COUNT"
## [22] "COVID_DEATH_RATE" "PERCENT_POSITIVE.x" "TOTAL_COVID_TESTS.x"
## [25] "COVID_CASE_COUNT.y" "COVID_CASE_RATE.y" "PERCENT_POSITIVE.y"
## [28] "TOTAL_COVID_TESTS.y" "geometry"
mapview(ZipCovidsf,
zcol = "COVID_CASE_COUNT.x",
legend = TRUE,
col.regions = colorRampPalette(c("lightblue", "yellow", "red"))(100))
## Warning: Found less unique colors (100) than unique zcol values (174)!
## Interpolating color vector to match number of zcol values.
# Filter nursing homes
NursingHomes <- HealthFacilitiesCsv %>%
dplyr::filter(`Short.Description` == "NH") %>%
dplyr::group_by(`Facility.Zip.Code`)
# Combine
ZipCovidNHsf <- ZipCovidsf %>%
left_join(NursingHomes, by = c("ZIPCODE" = "Facility.Zip.Code"))
## Warning in sf_column %in% names(g): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 6 of `x` matches multiple rows in `y`.
## ℹ Row 5 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
# Check, looks right
mapview(ZipCovidNHsf, zcol = "ZIPCODE", legend = TRUE)