Set-Up:

R Spatial Lab Assignment # 3

Task 1:

Task 2:

Use ggplot2 and other ggplot-compatible packages to create a multi-map figure illustrating the possible relationship between COVID-19 confirmed cases or rate and another factor (e.g., the number of nursing homes, number of food stores, neighborhood racial composition, elderly population, etc.). The maps should be put side by side on one single page. Add graticule to at least one of those maps and label some of the feature on the map where applicable and appropriate.

ggplot(NYC_Final)+ 
  geom_sf(aes(fill=COVID_CASE_COUNT))+
  geom_sf(aes(fill=whitePop))

breaks_VidCount <- classIntervals(c(min(NYC_Final$COVID_CASE_COUNT) - .00001,
                                   NYC_Final$COVID_CASE_COUNT), n = 6, style = "quantile") # creates 6 catagories 

#creates a new column to store the new labeled categories and sorts by count into them 
NYC_Final <- mutate(NYC_Final, 
                            covid_cat = cut(COVID_CASE_COUNT, breaks_VidCount$brks,
                                            labels = c("Extremely Low", "Very Low", "Low", "Moderate", "High", "Very High"),# Labels here so the key will look nice  
                                            dig.lab = 4, digits=1)) 
#plot:
plot1 <- ggplot(NYC_Final) + 
  geom_sf(aes(fill=covid_cat))+
  scale_fill_brewer(palette = rev("Greens"), name='Covid Case Amounts') +
  labs(x='Longitude', y='Latitude', 
       title='NYC Covid Case Counts')+
  coord_sf(crs = st_crs(2263))

 
##Same Idea for plot 2, create breaks, then new columnn and sort by catagory 

breaks_stores <- classIntervals(c(min(NYC_Final$n_stores) - .00001,
                                  NYC_Final$n_stores), n = 5, style = "quantile") # creates 5 categories 
## Warning in classIntervals(c(min(NYC_Final$n_stores) - 1e-05,
## NYC_Final$n_stores), : var has missing values, omitted in finding classes
#creates a new column to store the new labeled categories and sorts by count into them 
NYC_Final <- mutate(NYC_Final, 
                    store_cat = cut(n_stores, breaks_stores$brks,
                                    labels = c("Very Low", "Low", "Moderate", "High", "Very High"),# Labels here so the key will look nice  
                                    dig.lab = 4, digits=1))


plot2<- ggplot(NYC_Final) + 
  geom_sf(aes(fill=store_cat))+
  scale_fill_brewer(palette = "Reds", name='Food Store Amounts') +
  labs(x='Longitude', y='Latitude', 
       title='NYC Food Store Counts')+
  coord_sf(crs = st_crs(2263))

##Plotted both maps side by side 
ggarrange(plot1, plot2, nrow = 1, ncol = 2)

Task 3:

Create a web-based interactive map for COIVD-19 data using tmap, mapview, or leaflet package and save it as a HTML file.

#tmap store count 
tm_shape(NYC_Final) +
  tm_polygons("n_stores", 
              style="jenks", 
              title="NYC \nStores",
              palette = "brewer.blues",
              border.col = "black",
              border.alpha = 0.5) +
  tm_layout(title = "Store Distribution in NYC")
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'
## [v3->v4] `tm_polygons()`: use 'fill' for the fill color of polygons/symbols
## (instead of 'col'), and 'col' for the outlines (instead of 'border.col').
## [v3->v4] `tm_polygons()`: use `col_alpha` instead of `border.alpha`.
## [v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'
## [v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`

tmap_mode("view")
## ℹ tmap mode set to "view".
#save as HTML
tmap_save(tmap_last(), "NYC_Map.html")
## [v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(title = )`
## 
## 
## ── tmap v3 code detected ───────────────────────────────────────────────────────
## 
## [v3->v4] `tm_polygons()`: instead of `style = "jenks"`, use fill.scale =
## `tm_scale_intervals()`.
## ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
##   'tm_scale_intervals(<HERE>)'
## [v3->v4] `tm_polygons()`: use `col_alpha` instead of `border.alpha`.
## [v3->v4] `tm_polygons()`: migrate the argument(s) related to the legend of the
## visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'
## Interactive map saved to C:\Users\Admin\OneDrive\Documents\Data & Vis in R\Week7_10\R_project7_10\NYC_Map.html