NYC Restaurant Inspection

Use the NYC Restaurant Inspections dataset to create three distinct plot types using plotly.

library(tidyverse)
library(p8105.datasets)
library(plotly)

data("rest_inspec")


Plotly Boxplot

First, we want to take a look at the score distribution of A grade restaurants by each boro using a Plotly boxplot.

plotly_box = rest_inspec %>%
  filter(
    grade == "A", boro != "Missing") %>% 
  mutate(
    text_label = str_c("Score: ", score)
  ) %>% 
  plot_ly(
    y = ~score, color = ~boro,
    type = "box", mode = "markers",
    alpha = .5, text = ~text_label
  )

plotly_box = plotly_box %>% 
  layout(
    title = "The distribution of score by boro",
    xaxis = list(title = "Boro"),
    yaxis = list(title = "Score"),
    legend = list(title = list(text = '<b> Boro </b>'), y = 0.5))

plotly_box


Plotly Barchart

Then, we want to take a look at the counts of A grade restaurants (n > 1000) in Manhattan by each cuisine type using a Plotly barchart.

plotly_bar = rest_inspec %>% 
  filter(grade == "A", boro == "MANHATTAN", cuisine_description != "Not Listed/Not Applicable") %>% 
  count(cuisine_description) %>% 
  filter(n > 1000) %>% 
  mutate(
    text_label = str_c("Number: ", n),
    cuisine_description = recode(cuisine_description, "Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin"),
    cuisine_description = fct_reorder(cuisine_description, n)
  ) %>% 
  plot_ly(
    x = ~cuisine_description, y = ~n, color = ~cuisine_description,
    type = "bar", mode = "markers",
    alpha = .5, text = ~text_label
  )

plotly_bar = plotly_bar %>% 
  layout(
    title = "The number of A grade restaurants in Manhattan",
    xaxis = list(title = "Cuisine Type"),
    yaxis = list(title = "Count"),
    legend = list(title = list(text = '<b> Cuisine Type </b>'), y = 0.5))

plotly_bar


Plotly Scatterplot

Lastly, we can take a closer look at the score distribution of all Chinese restaurants in Manhattan by grade date using a Plotly scatterplot.

plotly_scatter = rest_inspec %>% 
  filter(
    boro == "MANHATTAN", str_detect(cuisine_description, "[Cc][Hh][Ii][Nn][Ee][Ss][Ee]"), grade != "Not Yet Graded") %>% 
  mutate(
    text_label = str_c("Grade: ", grade, "\nScore: ", score)
  ) %>% 
  plot_ly(
    x = ~grade_date, y = ~score, color = ~grade,
    type = "scatter", mode = "markers",
    alpha = 1, text = ~text_label
  )

plotly_scatter = plotly_scatter %>% 
  layout(
    title = "The distribution of score by grade date",
    xaxis = list(title = "Grade Date"),
    yaxis = list(title = "Score"),
    legend = list(title = list(text = '<b> Grade </b>'), y = 0.5))

plotly_scatter


Other Materials

Go to Landing Page.
Go to Resume.
Go to Dashboard.