Use st_read to read the Geo package and the COVID population by zip code layer
acsCovidData <- st_read("/Users/elvagao/Desktop/Rstudio_GTECH/R-spatial_3/acsPopByZip.gpkg", layer = "NYC_Covid_Pop_by_Zip")
## Reading layer `NYC_Covid_Pop_by_Zip' from data source
## `/Users/elvagao/Desktop/Rstudio_GTECH/R-spatial_3/acsPopByZip.gpkg'
## using driver `GPKG'
## Simple feature collection with 180 features and 13 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: 913129 ymin: 120020.9 xmax: 1067113 ymax: 272710.9
## Projected CRS: NAD83 / New York Long Island (ftUS)
View the rows of the data and the structure
colnames(acsCovidData)
## [1] "ZIPCODE" "PO_NAME" "POPULAT" "COUNTY" "Positiv" "Total" "totPop"
## [8] "malPctg" "asianPp" "blackPp" "hspncPp" "whitePp" "eldrlyP" "geom"
use ggplot to plot covid data
ggplot(data = acsCovidData) +geom_sf(aes(fill = Positiv), color = "white", size = 0.2) + scale_fill_viridis_c() + labs(title = "COVID-19 Confirmed Cases by Zip Code", fill = "Confirmed Cases") + theme_minimal() + theme(legend.position = "right")
use ggplot to plot asian population with another color
ggplot(data = acsCovidData) + geom_sf(aes(fill = asianPp), color = "green", size = 0.2) + scale_fill_viridis_c() + labs(title = "Asian Population by Zip Code", fill = "Asian Population") + theme_minimal() + theme(legend.position = "right")
put covid data plot on the right side
Covidmap <- ggplot(data = acsCovidData) + geom_sf(aes(fill = Positiv), color = "white", size = 0.2) + scale_fill_viridis_c() + labs(title = "COVID-19 Confirmed Cases by Zip Code", fill = "Confirmed Cases") + theme_minimal() + theme(legend.position = "right")
put asian plot data on the left side
Asianmap <- ggplot(data = acsCovidData) +geom_sf(aes(fill = asianPp), color = "green", size = 0.2) + scale_fill_viridis_c() + labs(title = "Asian Population by Zip Code", fill = "Asian Population") + theme_minimal() + theme(legend.position = "right")
put both plot together side by side
ggarrange(Covidmap, Asianmap, ncol = 2, nrow = 1)
Interactive map and convert to leaflet in order for it to be saved and then save leaflet as html
interactive_map <- mapview(acsCovidData, zcol = "Positiv")
leaflet_map <- interactive_map@map
saveWidget(leaflet_map, "COVID_map.html")