Selection strategies

Intermediate Interactive Data Visualization with plotly in R

Adam Loy

Statistician, Carleton College

Two selection strategies

Transient selection

previously selected cases are forgotten

linking_teaser1.gif

Persistent selection

selected cases accumulate

linking_teaser2.gif

Intermediate Interactive Data Visualization with plotly in R

Example

before_persistent_selection.png

Intermediate Interactive Data Visualization with plotly in R

Generate the base chart

shared_data <- world2014 %>% SharedData$new()

p1 <- shared_data %>%
  plot_ly(x=~urban/population, y = ~co2, text = ~country) %>%
  add_markers()

p2 <- shared_data %>%
  plot_ly(x=~income, y = ~co2, text = ~country) %>%
  add_markers()

subplot(p1, p2, titleX = TRUE, shareY = TRUE) %>% 
  hide_legend()
Intermediate Interactive Data Visualization with plotly in R

Persistent selection

Activate persistent selection via highlight()

subplot(p1, p2, titleX = TRUE, shareY = TRUE) %>% 
  hide_legend() %>%
  highlight(persistent = TRUE)

persistent_selection.gif

Intermediate Interactive Data Visualization with plotly in R

Highlighting in color

dynamic_selection.gif

Intermediate Interactive Data Visualization with plotly in R

Highlighting in color

Add dynamic = TRUE to activate a color picker

subplot(p1, p2, titleX = TRUE, shareY = TRUE) %>% 
  hide_legend() %>%
  highlight(persistent = TRUE, dynamic = TRUE)
Intermediate Interactive Data Visualization with plotly in R

Two manipulation types

Direct manipulation

selection performed by interacting with the graphical elements

linking_teaser1.gif

Indirect manipulation

selection performed via query outside of the chart

indirect_manipulation.gif

Intermediate Interactive Data Visualization with plotly in R

select_time_series.gif

Intermediate Interactive Data Visualization with plotly in R

Indirect manipulation

world_indicators %>%
  SharedData$new(key = ~country) %>% 
  plot_ly(x = ~year, y = ~income, alpha = 0.5) %>%
  group_by(country) %>%
  add_lines()
Intermediate Interactive Data Visualization with plotly in R

Indirect manipulation

world_indicators %>%
  SharedData$new(key = ~country, group = "Select a country") %>% 
  plot_ly(x = ~year, y = ~income, alpha = 0.5) %>%
  group_by(country) %>%
  add_lines() %>%
  highlight(selectize = TRUE)
Intermediate Interactive Data Visualization with plotly in R

indirect_manipulation.gif

Intermediate Interactive Data Visualization with plotly in R

Let's practice!

Intermediate Interactive Data Visualization with plotly in R

Preparing Video For Download...