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:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.
covid_2021_04_23 <- st_read(‘R-Spatial_II_Lab/tests-by-zcta_2021_04_23.csv’, stringsAsFactors = FALSE)
covid_merge <- base::merge(covid_2021_04_23, nyc_040114, by.x = “MODIFIED_ZCTA”, by.y = “ZIPCODE”) # Make sf covid_merge_sf <- st_as_sf(covid_merge)
nys_rfs_food <- st_transform(nys_rfs_sf, st_crs(nyc_040114))
nyc_food <- nys_rfs_food %>% filter( Establishment.Type == “A”, County %in% c(“New York”, “Kings”, “Queens”, “Bronx”, “Richmond”) )
nyc_food_merge <- st_join(nyc_food, nyc_040114, join = st_within)
zip_food_count <- nyc_food_merge %>% filter(!is.na(ZIPCODE)) %>% st_drop_geometry() %>% group_by(ZIPCODE) %>% summarise(store_count = n())
nyc_zip_counts <- nyc_040114 %>% left_join(zip_food_count, by = “ZIPCODE”)
mapview(nyc_zip_counts , zcol = “store_count”)
nys_hf_sf <- st_transform(nys_hf_sf, st_crs(nyc_040114))
nyc_nh <- nys_hf_sf %>% filter( Short.Description == “NH”, Facility.County %in% c(“New York”, “Kings”, “Queens”, “Bronx”, “Richmond”) )
nyc_nh_merge <- st_join(nyc_nh, nyc_040114, join = st_within)
nyc_nh_count <- nyc_nh_merge %>% filter(!is.na(ZIPCODE)) %>% st_drop_geometry() %>% group_by(ZIPCODE) %>% summarise(nh_count = n())
nyc_nh_count <- nyc_040114 %>% left_join(nyc_nh_count, by = “ZIPCODE”)
mapview(nyc_nh_count , zcol = “nh_count”)
nycCensus %<>% 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 <- readLines(
“R-Spatial_II_Lab/ACSDP5Y2018.DP05_data_with_overlays_2020-04-22T132935.csv”
) %>% magrittr::extract(-2) %>% textConnection() %>%
read.csv(header=TRUE, quote= “"”) %>% dplyr::select(GEO_ID, totPop =
DP05_0001E, elderlyPop = DP05_0024E, malePop = DP05_0002E, femalePop =
DP05_0003E,
whitePop = DP05_0037E, blackPop = DP05_0038E, asianPop = DP05_0067E,
hispanicPop = DP05_0071E, adultPop = DP05_0021E, citizenAdult =
DP05_0087E) %>% dplyr::mutate(censusCode = stringr::str_sub(GEO_ID,
-9,-1));
popData <- merge(nycCensus, acsData, by.x =‘tractFIPS’, by.y = ‘censusCode’)
popData <- sf::st_transform(popData, st_crs(nyc_040114))
covidPopZipNYC <- sf::st_join(covid_merge_sf, popData %>% sf::st_centroid(), join = st_contains) %>% group_by(MODIFIED_ZCTA, PO_NAME, POPULATION, COUNTY, COVID_CASE_COUNT, TOTAL_COVID_TESTS) %>% summarise(totPop = sum(totPop), malePctg = sum(malePop)/totPop*100, asianPop = sum(asianPop), blackPop = sum(blackPop), hispanicPop = sum(hispanicPop), whitePop = sum(whitePop))