Update the title with your information. Make sure to include identification information so that we know it is your submission.
Also update the author name and date accordingly.
Check out the Source Code from the top-right corner
</>Code
menu.
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.
smpCode <- "hello, R markdown and RPubs!"
cat(smpCode)
## hello, R markdown and RPubs!
Quarto markdown is different from R markdown in terms of chunk options. See chunk options at Quarto website.
print("This is the new code chunk options available in Quarto Markdown")
## [1] "This is the new code chunk options available in Quarto Markdown"
# Prepare data to group maps together
plot1 <- ggplot(ACSCovidData) +
geom_sf(aes(fill = POPULAT)) +
scale_fill_viridis_c(
name = "Population",
labels = comma
) +
labs(title = "NYC Population (per square km)")
# Label locations on map with over 1500 cases
label_data2 <- ACSCovidData %>%
sf::st_point_on_surface() %>%
filter(Positiv > 1500) %>%
mutate(
coords = sf::st_coordinates(.),
x = coords[,1],
y = coords[,2],
POP_COMMA = comma(Positiv)
)
## Warning: st_point_on_surface assumes attributes are constant over geometries
# Plot with labels using geom_label_repel
plot2 <- ggplot(ACSCovidData) +
geom_sf(aes(fill = Positiv)) +
scale_fill_viridis_c(
name = "Cases",
labels = comma
) +
geom_label_repel(
data = label_data2,
aes(x = x, y = y, label = POP_COMMA),
label.size = 0.1,
size = 3,
segment.color = "grey50",
segment.size = 0.6,
box.padding = 0.5,
force = 5,
max.overlaps = 100 # ← this line prevents that warning!
) +
labs(
title = "NYC Cases (per square km)",
x = "Longitude",
y = "Latitude"
) +
coord_sf()
# Arrange maps together, ensure they are the same size
ggarrange(plot1, plot2, nrow = 1, ncol = 2, align ="h")
# Create interactive map
interactive_map <- mapview(ACSCovidData, zcol = "Positiv")
# Convert to leaflet
leaflet_map <- interactive_map@map
# Save as html
saveWidget(leaflet_map, "COVID_map.html")