Customize your traces

Interactive Data Visualization with plotly in R

Adam Loy

Statistician, Carleton College

Wine quality data

glimpse(winequality)
Rows: 325
Columns: 14
$ type             <chr> "red", "red", "red", "red", "red", "red", ...
$ fixed_acidity    <dbl> 8.2, 8.2, 8.0, 10.2, 8.6, 6.1, 10.7, 9.1, 7.2...
$ volatile_acidity <dbl> 0.885, 0.640, 0.715, 0.360, 0.520, 0.590, 0.6...
$ citric_acid      <dbl> 0.20, 0.27, 0.22, 0.64, 0.38, 0.01, 0.22, 0.3...
$ residual_sugar   <dbl> 1.40, 2.00, 2.30, 2.90, 1.50, 2.10, 2.70, 2.1...
...
$ sulphates        <dbl> 0.46, 0.62, 0.54, 0.66, 0.52, 0.56, 0.98, 0.8...
$ alcohol          <dbl> 10.0, 9.1, 9.5, 12.5, 9.4, 11.4, 9.9, 11.2, 1...
$ quality          <int> 5, 6, 6, 6, 5, 5, 6, 6, 6, 7, 6, 5, 4, 6, 6, ...
$ quality_label    <chr> "low", "medium", "medium", "medium", "low", ...
Interactive Data Visualization with plotly in R

Color

winequality %>%
   plot_ly(x = ~fixed_acidity) %>%  
   add_histogram()
Interactive Data Visualization with plotly in R

Color

winequality %>%
   plot_ly(x = ~fixed_acidity) %>%  
   add_histogram(color = I("red")) # Setting color
Interactive Data Visualization with plotly in R

Opacity

winequality %>%
  plot_ly(x = ~residual_sugar, y = ~fixed_acidity) %>%
  add_markers()
Interactive Data Visualization with plotly in R

Opacity

winequality %>%
  plot_ly(x = ~residual_sugar, y = ~fixed_acidity) %>%
  add_markers(marker = list(opacity = 0.2))           # Adjust opacity
Interactive Data Visualization with plotly in R

Symbols

winequality %>%
  plot_ly(x = ~residual_sugar, y = ~fixed_acidity) %>%
  add_markers(marker = list(symbol = "circle-open"))   # Change symbol
Interactive Data Visualization with plotly in R

Marker options

  • opacity
  • color
  • symbol (scatter/box)
  • size (scatter)
  • width (bar/histogram)
Interactive Data Visualization with plotly in R

Let's practice!

Interactive Data Visualization with plotly in R

Preparing Video For Download...