library(tidyverse)
library(ggmap)
# set default theme
theme_set(theme_minimal())
Drawing maps with ggmap
Packages
Load NYC 311 reports
Let’s first load a subset of 311 service requests in New York City.1
# load data
<- read_csv(file = "data/nyc-311.csv")
nyc_311 glimpse(nyc_311)
This subset includes 311 service requests related to Food Poisoning in commercial establishments (e.g. restaurants, cafeterias, food carts).
Register a Stadia Maps API Key
Your turn: Store your Stadia Maps API key using the function
register_stadiamaps(key = "YOUR-API-KEY", write = TRUE)
replacing "YOUR-API-KEY"
with your actual API key. Otherwise you will not be able to obtain map tiles and complete the application exercise.
Obtain map tiles for New York City
Your turn: Use bboxfinder.com to find bounding box coordinates for New York City. Then, use get_stamenmap()
to obtain map tiles for New York City and visualize the map.
I recommend a zoom
level of 11.
# store bounding box coordinates
<- c(
nyc_bb left = TODO,
bottom = TODO,
right = TODO,
top = TODO
)
<- get_stadiamap(
nyc bbox = nyc_bb,
zoom = TODO
)
# plot the raster map
TODO(nyc)
Food poisoning rates
The COVID-19 pandemic caused massive disruption in the restaurant industry. Due to social distancing measures and lockdowns, restaurant traffic decreased significantly.
While this had significant financial ramifications, one potentially overlooked consequence is the impact on food poisoning rates. With fewer people eating out, the number of food poisoning complaints may have decreased.
Your turn: Visualize the geospatial distribution of complaints related to food poisoning in NYC in March, April, and May over a four-year time period (2018-21). Construct the chart in such a way that you can make valid comparisons over time and geographically. What impact did COVID-19 have on food poisoning cases in NYC? Did it vary geographically?
<- nyc_311 |>
nyc_covid_food_poison # generate a year variable
mutate(year = year(created_date)) |>
# only keep reports in March, April, and May from 2018-21
filter(month(created_date) %in% 3:5, year %in% 2018:2021)
# add code here
Visualize food poisoning complains on Roosevelt Island
Your turn: Now focus on food poisoning complaints on or around Roosevelt Island.2 Use get_stamenmap()
to obtain map tiles for the Roosevelt Island region and overlay with the food poisoning complaints. What type of chart is more effective for this task?
Consider adjusting your zoom
for this geographic region.
# Obtain map tiles for Roosevelt Island
<- c(
roosevelt_bb left = TODO,
bottom = TODO,
right = TODO,
top = TODO
)<- get_stadiamap(
roosevelt bbox = roosevelt_bb,
zoom = TODO
)
# add code here
Footnotes
These reports were obtained from the NYC Open Data portal API.↩︎
Also the location of Cornell Tech.↩︎