Herhaling: Animatie

Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Adam Loy

Statistician, Carleton College

Keyframe-animatie

Filmstrook van scatterplots.

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_markers(frame = ~year, ids = ~country, showlegend = FALSE)
Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Geanimeerde tijdreeks van België’s inkomen per hoofd.

Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Cumulatieve animaties

library(dplyr)
library(purrr)
belgium %>%
  split(.$year) %>%
  accumulate(~bind_rows(.x, .y)) %>%
  set_names(1960:2018) %>%
  bind_rows(.id = "frame")
Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Omgaan met gespreide startpunten

CRAN-downloadanimatie.

Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

CRAN-downloadgegevens

glimpse(monthly_logs)
Rows: 171
Columns: 4
$ package   <chr> "ggvis", "ggvis", "ggvis", "ggvis", "ggvis", "ggvis",…
$ date      <date> 2014-06-30, 2014-07-31, 2014-08-31, 2014-09-30, 2014…
$ dec_date  <dbl> 2014.49, 2014.58, 2014.66, 2014.75, 2014.83, 2014.91,…
$ downloads <dbl> 1344, 2120, 2035, 1702, 3590, 2899, 2427, 2227, 2708,…
Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Wat als we de baseline negeren?

monthly_logs %>%
  split(f = .$dec_date) %>%
  accumulate(., ~bind_rows(.x, .y)) %>%
  bind_rows(.id = "frame") %>%
  plot_ly(x = ~dec_date, y = ~downloads) %>%
  add_lines(color = ~package, frame = ~frame, ids = ~package)
Warning message:
In p$x$data[firstFrame] <- p$x$frames[[1]]$data :
  number of items to replace is not a multiple of replacement length
Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

De dataset aanvullen

library(tidyr)
complete_logs <- monthly_logs %>% complete(package, dec_date, fill = list(downloads = 0))

arrange(complete_logs, dec_date)
## A tibble: 228 x 4
  package     dec_date date       downloads
  <chr>          <dbl> <date>         <dbl>
1 ggvis          2014. 2014-06-30      1344
2 highcharter    2014. NA                 0
3 plotly         2014. NA                 0
4 rbokeh         2014. NA                 0
5 ggvis          2015. 2014-07-31      2120
# … with 223 more rows
Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

De aangevulde data animeren

complete_logs %>%
  split(f = .$dec_date) %>%
  accumulate(., ~bind_rows(.x, .y)) %>%
  bind_rows(.id = "frame") %>%
  plot_ly(x = ~dec_date, y = ~downloads) %>%
  add_lines(color = ~package, frame = ~frame, ids = ~package)

CRAN-downloadanimatie, kleine GIF.

Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Laten we oefenen!

Gemiddeld gevorderde interactieve datavisualisatie met plotly in R

Preparing Video For Download...