Slides – http://bit.ly/JSM_16

Why interactive graphics?

  • Why should presentation graphics be interactive?
    • Helps demonstrate your point
  • Why should exploratory graphics be interactive?
    • Generate insight faster (thus, iteration time is crucial!).
Technique Related Question(s) Examples
Identification What is this point/mark? Hover for additional info
Filter How does one group compare to another?
What happened during this time period?
shiny::selectInput()
shiny::sliderInput()
Click on legend entries
Zoom & pan Is there local structure? Click & drag to alter x/y limits
Linked highlighting How does the marginal/joint compare to a conditional? Linked brushing on a scatterplot matrix

Why web graphics? Composable! Easy to Share!

Problem: Web graphics usually aren't practical for exploring data

Good for presentation (viz type is known), bad for exploration (viz type is unknown)

Identification, zoom & pan w/ ggplotly

library(plotly)
p <- qplot(data = diamonds, x = carat, y = price, color = cut, alpha = I(.05))
toWebGL(ggplotly(p))

Disclaimer

The following examples are very new, may change, and require dev versions of several packages:

library(devtools)
install_github("rstudio/crosstalk")
install_github("ropensci/plotly@joe/feature/crosstalk")
install_github("rstudio/leaflet@joe/feature/crosstalk-filter")

Highlighting series

library(crosstalk)
d <- SharedData$new(txhousing, ~city)
p <- qplot(data = d, x = date, y = median, group = city, geom = "line")
o <- ct_opts(on = "plotly_hover", off = "plotly_doubleclick", color = "red")
ggplotly(p, tooltip = "city", crosstalkOpts = o)

Extending James' ggplot

Linked highlighting via ggplotly

Linked brushing in plotly via crosstalk

library(crosstalk)
d <- SharedData$new(mtcars)
subplot(
  qplot(data = d, x = mpg, y = wt),
  qplot(data = d, x = mpg, y = vs)
)

Linked brushing with plotly & leaflet

library(leaflet)
sd <- SharedData$new(quakes)
p <- plot_ly(sd, x = ~depth, y = ~mag) %>% add_markers(alpha = 0.5)
map <- leaflet(sd) %>% addTiles() %>% addCircles()
htmltools::tagList(list(p, map))

library(GGally)
iris$id <- seq_len(nrow(iris))
d <- SharedData$new(iris, ~id)
p <- ggpairs(d, aes(colour = Species), columns = 1:4)
ggplotly(p, c("x", "y", "colour"))

Limitations

Identity mapping between plot & data

Limitations continued

p <- qplot(data = mtcars, x = mpg)
ggplotly(p, originalData = FALSE) %>% plotly_data()
#> # A tibble: 30 x 17
#>        y count        x     xmin     xmax    density ncount  ndensity
#> *  <dbl> <dbl>    <dbl>    <dbl>    <dbl>      <dbl>  <dbl>     <dbl>
#> 1      2     2 10.53448 10.12931 10.93966 0.07712766    0.4 10.372414
#> 2      0     0 11.34483 10.93966 11.75000 0.00000000    0.0  0.000000
#> 3      0     0 12.15517 11.75000 12.56034 0.00000000    0.0  0.000000
#> 4      1     1 12.96552 12.56034 13.37069 0.03856383    0.2  5.186207
#> 5      0     0 13.77586 13.37069 14.18103 0.00000000    0.0  0.000000
#> 6      2     2 14.58621 14.18103 14.99138 0.07712766    0.4 10.372414
#> 7      5     5 15.39655 14.99138 15.80172 0.19281915    1.0 25.931034
#> 8      1     1 16.20690 15.80172 16.61207 0.03856383    0.2  5.186207
#> 9      1     1 17.01724 16.61207 17.42241 0.03856383    0.2  5.186207
#> 10     2     2 17.82759 17.42241 18.23276 0.07712766    0.4 10.372414
#> # ... with 20 more rows, and 9 more variables: PANEL <int>, group <int>,
#> #   ymin <dbl>, ymax <dbl>, colour <lgl>, fill <chr>, size <dbl>,
#> #   linetype <dbl>, alpha <lgl>

Where should the computation live?

Thank you to sooo many people

  • The plotly.js team
  • The RStudio team
  • Heike Hofmann
  • Di Cook
  • Toby Dylan Hocking
  • Barret Schloerke
  • and many more…

Thank you!