---
title: "Dashboard for Instacart Online Grocery Shopping Dataset"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
navbar:
- { icon: fa-home, href: index.html, align: right }
- { icon: fa-linkedin, href: https://www.linkedin.com/in/yijia-jiang/, align: right }
- { icon: fa-envelope, href: mailto:<yj2687@cumc.columbia.edu>, align: right }
- { icon: fa-github, href: https://github.com/YijiaJiang/, align: right }
source_code: embed
theme:
bootswatch: minty
includes:
in_header: icon.html
---
```{r set up,include=FALSE}
library(flexdashboard)
library(tidyverse)
library(p8105.datasets)
library(plotly)
```
```{r,message=FALSE,warning=FALSE}
data("instacart")
instacart_df =
instacart %>%
as_tibble(instacart) %>%
janitor::clean_names() %>%
mutate(day = order_dow + 1, day_of_week = lubridate::wday(day, label = TRUE)) %>%
mutate(time = paste(as.character(order_hour_of_day),"00",sep = ":")) %>%
select(order_id, product_id, order_number, day_of_week, time, product_name, aisle, department) %>%
drop_na()
```
Column {data-width=610}
-----------------------------------------------------------------------
### Line Chart: Order Quantity Change Over Time
```{r,message=FALSE,warning=FALSE}
instacart_df %>%
mutate(time = factor(time, levels = c("0:00","1:00", "2:00", "3:00","4:00","5:00","6:00","7:00","8:00","9:00",
"10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00",
"19:00","20:00","21:00","22:00","23:00"))) %>%
count(time, department) %>%
plot_ly(x = ~time, y = ~n, alpha = 0.8,
type = "scatter", mode = "lines+markers", color = ~str_to_title(department)) %>%
layout(xaxis = list(title = "Time"), yaxis = list(title = "Number of Orders"),
font = list(size = 10.5))
```
Column {data-width=390}
-----------------------------------------------------------------------
### Bar Plot: Number of Items Ordered in Each Aisle
```{r,message=FALSE,warning=FALSE}
instacart_df %>%
count(aisle) %>%
filter(n > 20000) %>%
mutate(aisle = str_to_title(aisle)) %>%
mutate(aisle = fct_reorder(aisle, -n)) %>%
plot_ly(x = ~aisle, y = ~n, color = ~aisle, type = "bar") %>%
layout(xaxis = list(title = "Aisle"), yaxis = list(title = "Number of Orders"),
font = list(size = 10.5)) %>%
hide_legend()
```
### Boxplot: Order Quantity Distribution for Each Day
```{r,message=FALSE,warning=FALSE}
instacart_df %>%
plot_ly(y = ~order_number, color = ~day_of_week, type = "box", alpha = 0.6) %>%
layout(font = list(size = 10.5), yaxis = list(title = "Number of Orders"),
xaxis = list(title = "Day", categoryorder = "array", categoryarray = c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"))) %>%
hide_legend()
```