Author

Antonio Osso

Published

March 27, 2026

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.

R Spatial Lab Assignment # 3

task 1:

Code
acsdata <- st_read("acsPopByZip.gpkg")
Reading layer `NYC_COVID_Pop_by_Zip' from data source 
  `C:\Users\Antonio\Documents\Week9\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)
Code
breaks_q1 <- classIntervals(c(min(acsdata$Positiv) - 0.00001, acsdata$Positiv), n=5, style = "quantile")
acsdata_q1 <- mutate(acsdata, positive_cat = cut(acsdata$Positiv, breaks_q1$brks, dig.lab=4, digits=1))
cov_map <- ggplot(acsdata_q1) + geom_sf(aes(fill=positive_cat)) + 
  scale_fill_brewer(palette = "YlGnBu", name='Total Positive Cases') + 
     coord_sf(default_crs = sf::st_crs(4326)) + 
                labs(x='Longitude', y='Latitude', title='Positive COVID-19 Cases by Zip Code') + theme(legend.position =  "right") + annotation_north_arrow(location="tl", which_north="true") + annotation_scale(location= "br")
plot(cov_map)

Code
breaks_q1pt2 <- classIntervals(c(min(acsdata$eldrlyP) - 0.00001, acsdata$eldrlyP), n=5, style = "quantile")
Warning in classIntervals(c(min(acsdata$eldrlyP) - 1e-05, acsdata$eldrlyP), :
var has missing values, omitted in finding classes
Code
acsdata_q1pt2 <- mutate(acsdata, elderly_cat = cut(acsdata$eldrlyP, breaks_q1pt2$brks, dig.lab = 4, digits=1))
eld_map <- ggplot(acsdata_q1pt2) + geom_sf(aes(fill=elderly_cat)) + scale_fill_brewer(palette = "RdPu", name='Elderly Population') +
            coord_sf(default_crs = sf::st_crs(4326)) + labs(x='Longitude', y='Latitude', title='Elderly Population by Zipcode') + 
            theme(legend.position = "right") + annotation_north_arrow(location="tl", which_north="true") + annotation_scale(location= "br")
plot(eld_map)

task 2:

Code
cov_map + eld_map + plot_layout(ncol=2, nrow=1)

Code
#Attaching the PNG because the rendering came out weird.

Q2 Map

task 3:

Code
breaks_q3 <- classIntervals(c(min(acsdata$hspncPp) - 0.00001, acsdata$hspncPp), n=5, style="quantile")
Warning in classIntervals(c(min(acsdata$hspncPp) - 1e-05, acsdata$hspncPp), :
var has missing values, omitted in finding classes
Code
acsdataq3<- mutate(acsdata, hisp_cat = cut(acsdata$hspncPp, breaks_q3$brks, dig.lab = 4, digits=1))
tmap_mode("view")
ℹ tmap modes "plot" - "view"
ℹ toggle with `tmap::ttm()`
Code
q3_map <- tm_shape(acsdata_q1, name = "Covid Data") + tm_polygons("positive_cat", 
              style="quantile", title="COVID Cases by Zip Code", palette= "RdPu") + tm_shape(acsdata_q1pt2, 
              name = "Elderly Population") + tm_polygons("elderly_cat", style="quantile",
              title="Elderly Population by Zip Code", palette= "RdPu") + tm_shape(acsdataq3, name="Hispanic Population") + tm_polygons("hisp_cat",
                style="quantile", title="Hispanic Population by Zip Code", palette="RdPu")

── tmap v3 code detected ───────────────────────────────────────────────────────
[v3->v4] `tm_polygons()`: instead of `style = "quantile"`, use fill.scale =
`tm_scale_intervals()`.
ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to
  'tm_scale_intervals(<HERE>)'[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_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_polygons()`: migrate the argument(s) related to the legend of the
visual variable `fill` namely 'title' to 'fill.legend = tm_legend(<HERE>)'
Code
q3_map
[cols4all] color palettes: use palettes from the R package cols4all. Run
`cols4all::c4a_gui()` to explore them. The old palette name "RdPu" is named
"brewer.rd_pu"
Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.

Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.

Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.
Code
tmap_save(q3_map, filename = "CovidHTMLMap.html", selfcontained = TRUE)
[cols4all] color palettes: use palettes from the R package cols4all. Run
`cols4all::c4a_gui()` to explore them. The old palette name "RdPu" is named
"brewer.rd_pu"
Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.

Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.

Multiple palettes called "rd_pu" found: "brewer.rd_pu", "matplotlib.rd_pu". The first one, "brewer.rd_pu", is returned.

Interactive map saved to C:\Users\Antonio\Documents\Week9\CovidHTMLMap.html