Show the code
<- readRDS("nyc_covid.rds")
nyc_covid
plot(nyc_covid)
This Rpub includes the code used for week 08’ lab.
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.
Plot at least two high-quality static maps with one using the COVID-19 data and one using a related factor. You can use either plot method for sf or ggplot method.
<- readRDS("nyc_covid.rds")
nyc_covid
plot(nyc_covid)
<- readRDS("covidPopZipNYC.rds")
covidPopZipNYC
plot(
"whitePop"],
covidPopZipNYC[main = "White Covid Cases",
breaks = "quantile",
border = NA,
graticule = TRUE
)
plot(
"totPop"],
covidPopZipNYC[main = "Total Covid Cases",
breaks = "quantile",
border = NA,
graticule = TRUE
)
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.
<- classIntervals(c(min(covidPopZipNYC$asianPop) - .00001,
breaks_qt $asianPop), n = 6, style = "quantile")
covidPopZipNYC<- mutate(covidPopZipNYC,
covidPopZipNYC covid_cat = cut(asianPop, breaks_qt$brks,
labels = c("Extremely Low", "Very Low", "Low", "Moderate", "High", "Very High"),
dig.lab = 4, digits=1))
#plot:
<- ggplot(covidPopZipNYC) +
plot1geom_sf(aes(fill=covid_cat))+
scale_fill_brewer(palette = "OrRd", name='Covid Case Categories') +
labs(x='Longitude', y='Latitude',
title='Asian Covid Case')+
coord_sf(crs = st_crs(2263))
<- classIntervals(c(min(covidPopZipNYC$malePctg) - .00001,
breaks_male $malePctg), n = 2, style = "quantile") covidPopZipNYC
Warning in classIntervals(c(min(covidPopZipNYC$malePctg) - 1e-05,
covidPopZipNYC$malePctg), : var has missing values, omitted in finding classes
<- mutate(covidPopZipNYC,
MC_Final pt_cat = cut(malePctg, breaks_male$brks,
labels = c("Higher", "Lower"),
dig.lab = 2, digits=1))
<- ggplot(MC_Final) +
plot2geom_sf(aes(fill=pt_cat))+
scale_fill_brewer(palette = "Greens", name="Percentage/Threshold") +
labs(x='Longitude', y='Latitude',
title='Male Percentage')+
coord_sf(crs = st_crs(2263))
ggarrange(plot1, plot2, nrow = 1, ncol = 2)
Create a web-based interactive map for COVID-19 data using tmap, mapview, or leaflet package and save it as a HTML file.
<- tm_shape(covidPopZipNYC) +
covid_map tm_polygons("Positive",
palette = "Oranges",
title = "Positive COVID Cases",
border.col = "blue",
style = "quantile", # smart classification
n = 5) + # number of levels (optional)
tm_layout(title = "NYC Positive COVID Cases by ZIP Code")
── tmap v3 code detected ───────────────────────────────────────────────────────
[v3->v4] `tm_polygons()`: instead of `style = "quantile"`, use fill.scale =
`tm_scale_intervals()`.
ℹ Migrate the argument(s) 'style', 'n', '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()`: 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 = )`
covid_map
[cols4all] color palettes: use palettes from the R package cols4all. Run
`cols4all::c4a_gui()` to explore them. The old palette name "Oranges" is named
"brewer.oranges"
Multiple palettes called "oranges" found: "brewer.oranges", "matplotlib.oranges". The first one, "brewer.oranges", is returned.
# Save it as an HTML file
tmap_save(covid_map, "covid_map.html")
[cols4all] color palettes: use palettes from the R package cols4all. Run
`cols4all::c4a_gui()` to explore them. The old palette name "Oranges" is named
"brewer.oranges"
Multiple palettes called "oranges" found: "brewer.oranges", "matplotlib.oranges". The first one, "brewer.oranges", is returned.
Interactive map saved to D:\R-Spatial\covid_map.html