Adding layers

Intermediate Interactive Data Visualization with plotly in R

Adam Loy

Statistician, Carleton College

Increasing the slider text to 40 and changing the color to black.

Intermediate Interactive Data Visualization with plotly in R

Text layer

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_text(
    x = 6500, y = 1, text = ~year, frame = ~year,
    textfont = list(size = 150, color = toRGB("gray80"))
  )

23-text-only-animation.gif

Intermediate Interactive Data Visualization with plotly in R

Points layer

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_text(
    x = 6500, y = 1, text = ~year, frame = ~year,
    textfont = list(size = 150, color = toRGB("gray80"))
  ) %>%
  add_markers(frame = ~year, ids = ~country) %>%
  layout(
    xaxis = list(type = "log"), yaxis = list(type = "log")
  )
Intermediate Interactive Data Visualization with plotly in R

Polishing

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_text(
    x = 6500, y = 1, text = ~year, frame = ~year,
    textfont = list(size = 150, color = toRGB("gray80"))
  ) %>%
  add_markers(frame = ~year, ids = ~country) %>%
  layout(
    xaxis = list(type = "log"), yaxis = list(type = "log"),
    showlegend = FALSE
  ) %>%
  animation_slider(hide = TRUE)

23-polished.gif

Intermediate Interactive Data Visualization with plotly in R

23-polished.gif

Intermediate Interactive Data Visualization with plotly in R

Let's practice!

Intermediate Interactive Data Visualization with plotly in R

Preparing Video For Download...