library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(p8105.datasets)
library(dplyr)
library(tidyr)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggridges)
library(httr)
## 
## Attaching package: 'httr'
## The following object is masked from 'package:plotly':
## 
##     config
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
library(flexdashboard)

Column

Chart A

data("instacart")

instacart_1 =
  count(instacart, department) %>% 
  filter(department != "missing") %>% 
  arrange(n) %>% 
  mutate(
    department = factor(department, levels = department)
  )

instacart_1 %>% 
  plot_ly(x = ~n, y = ~department, color = ~department, type = "bar", colors = "viridis")

Column

Chart B

instacart_2 = instacart %>% 
  filter(department == "bakery") %>%
  mutate(department = str_to_title(department)) %>% 
  mutate(
    department = fct_infreq(department),
    department = fct_recode(department)) 
 

instacart_2 %>% 
  plot_ly(x = ~aisle, y = ~add_to_cart_order, color = ~aisle, alpha = .5,
    type = "scatter", mode = "markers"
  )

Chart C

data("instacart")

instacart_3 = instacart %>% 
  filter(department != "missing") %>% 
  mutate(department = str_to_title(department)) %>% 
  mutate(
    department = fct_infreq(department),
    department = fct_recode(department)) 
  

instacart_3 %>% 
  plot_ly(
      x = ~department, y = ~order_hour_of_day, color = ~department,
      type = "box", colors = "viridis"
    )