Examples

These examples as well as the dashboard in the next tab are done using the plotly library in R studio. A dataset called instacart was used to produce the following graphs below as well as the ones produced in the dashboard.

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

Scatter Graph

instacart %>% 
  count (aisle) %>% 
  filter ( n > 10000) %>% 
  plot_ly(x = ~aisle, y= ~n, color = ~aisle, type = "scatter")
## No scatter mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Bar Graph

instacart %>% 
  filter (aisle == c("fresh fruits", "fresh vegetables", "packaged vegetables fruits")) %>%
  group_by (aisle, product_name) %>% 
  summarize(n = n()) %>% 
  filter (min_rank(desc(n)) < 4) %>% 
  plot_ly(x = ~aisle, y = ~n, type = "bar")

Line Graph

instacart %>% 
  sample_n(10) %>%
  group_by(product_name, order_dow) %>% 
  summarize (mean=mean(order_hour_of_day)) %>% 
  plot_ly(x = ~mean, y = ~product_name, type= "scatter", mode = "line")