Chart 1, Sampled 5000 from the original dataset.

Chart 2

Chart 3, Sampled 2000 from the original dataset.

---
title: "RestaurantInspect Dashboard"
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    source_code: embed
    theme: bootstrap
editor_options: 
  chunk_output_type: console
---

```{r setup, include = FALSE}
library(tidyverse)
library(p8105.datasets)
library(flexdashboard)
library(plotly)
```


```{r, include = FALSE}
data("rest_inspec")

rest_inspec = 
  rest_inspec %>% 
  as_tibble(rest_inspec)
```


### Chart 1, Sampled 5000 from the original dataset.
```{r}
rest_inspec %>%
  sample_n(5000) %>%
  filter(boro != "Missing") %>%
  mutate(boro = fct_reorder(boro, score)) %>%
   plot_ly(
    y = ~score, color = ~boro,
    type = "box", colors = "viridis") %>%
  layout(title = "Score distributions in each boro")

```


### Chart 2

```{r}
rest_inspec %>%
  filter(boro == "MANHATTAN") %>%
  group_by(cuisine_description) %>%
  summarise(count = n()) %>%
  arrange(desc(count)) %>%
  head(10) %>%
  mutate(cuisine_description = fct_reorder(cuisine_description, count)) %>%
  mutate(cuisine_description = fct_rev(cuisine_description)) %>%
  mutate(cuisine_description = recode(cuisine_description, "Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin")) %>%
  plot_ly(
    x = ~cuisine_description,
    y = ~count,
    color = ~cuisine_description,
    type = "bar", colors = "viridis"
  ) %>%
  layout(title = "Cuisines with most restaurants in Manhattan", xaxis = list(title = "Cuisine"))
```


### Chart 3, Sampled 2000 from the original dataset.
```{r}
rest_inspec %>%
  filter(boro == "MANHATTAN", cuisine_description == "American") %>%
  sample_n(2000) %>%
  plot_ly(
    x = ~score,
    type = "histogram"
  ) %>%
  layout(title = "Score of American cuisine in Manhattan")
```