Setup
knitr::opts_chunk$set(fig.width=12, fig.height=8, fig.path='Figs/',
warning=FALSE, message=FALSE)
library(tidyverse)
library(httr)
library(jsonlite)
library(plotly)
library(leaflet)
library(knitr)
api_url = "https://data.cityofnewyork.us/resource/43nn-pn8j.csv"
rest_inspect =
GET(api_url, query = list("$limit" = 50000)) %>%
content("parsed")
rest_inspect = rest_inspect %>%
filter(grade %in% c("A", "B", "C"), boro != "0")
italian = c("Italian", "Italian/Pizza")
asian = c("Asian", "Japanese", "Korean", "Chinese")
Sys.setenv('MAPBOX_TOKEN' = 'pk.eyJ1IjoiYWFicmFtb3Y5MCIsImEiOiJja2gyZm5obzQwNWIxMnFxc3phcWh1MWtwIn0.amAvJHtFkTl9XWJ68fh96Q')
Restaurant Grades
Italian / Pizza Restaurants
rest_inspect %>%
filter(str_detect(cuisine_description, italian)) %>%
filter(latitude > 0) %>%
mutate(
text_label = str_c("Name: ", dba, "\nGrade: ", grade)) %>%
plot_mapbox(x = ~longitude, y = ~latitude, color =~grade, text =~text_label) %>%
layout(
mapbox = list(
zoom = 9,
center = list(lat = 40.67, lon = -73.97)))
French Restaurants
rest_inspect %>%
filter(str_detect(cuisine_description, "French")) %>%
filter(latitude > 0) %>%
mutate(
text_label = str_c("Name: ", dba, "\nGrade: ", grade)) %>%
plot_mapbox(x = ~longitude, y = ~latitude, color =~grade, text =~text_label) %>%
layout(
mapbox = list(
zoom = 9,
center = list(lat = 40.67, lon = -73.97)))
Asian Restaurants
rest_inspect %>%
filter(str_detect(cuisine_description, asian)) %>%
filter(latitude > 0) %>%
mutate(
text_label = str_c("Name: ", dba, "\nGrade: ", grade)) %>%
plot_mapbox(x = ~longitude, y = ~latitude, color =~grade, text =~text_label) %>%
layout(
mapbox = list(
zoom = 9,
center = list(lat = 40.67, lon = -73.97)))