Column

Chart A: Plotly scatterplot showing the distribution of the order sum in different aisles

Column

Chart B: Plotly barchart

Chart C: Plotly boxplot

---
title: "Order of Instacart"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    source_code: embed
    vertical_layout: fill
---

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

```{r}
data("instacart")
 instacart = 
   instacart%>% 
   # select 1000 samples
   sample_n(1000)
aisle_ordered = instacart %>%
  count(aisle) %>%
  rename(order_sum = n) %>%
  arrange(desc(order_sum))
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A: Plotly scatterplot showing the distribution of the order sum in different aisles 

```{r}
#this is a scatterplot showing the distribution of the order sum of different aisle 
aisle_ordered%>%
  plot_ly(x= ~aisle,
          y=~ order_sum, 
          type = "scatter",
          mode = "markers",
          marker = list(size=5),
          color = ~aisle,
          colors = "viridis",
          alpha = 0.5)%>%
  layout(title = "Distribution of order sum")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B: Plotly barchart

```{r}
aisle_ordered%>%
    mutate(aisle = as.factor(aisle),
         aisle = fct_reorder(aisle, order_sum))%>%
  plot_ly(x= ~aisle,
          y=~ order_sum, 
          type ="bar",
          mode = "markers",
          marker = list(size=5),
          color = ~aisle,
          colors = "viridis",
          alpha = 0.5)%>%
  layout(title = "Distribution of order sum")
```

### Chart C: Plotly boxplot

```{r}
instacart %>%
   group_by(aisle,product_name) %>% 
   summarize(order_sum = sum(order_number)) %>% 
   mutate(
     aisle = as.factor(aisle),
     aisle = fct_reorder(aisle, order_sum)) %>% 
   plot_ly(
     x = ~ aisle,
     y = ~ order_sum,
     type = "box",
     color = ~aisle,
     colors = "viridis",
          alpha = 0.5)%>%
  layout(title = "Distribution of order sum")
```