润色动画

R 中级交互式数据可视化(plotly)

Adam Loy

Statistician, Carleton College

自定义项

动画选项

  • 帧间时长
  • 帧过渡
  • 滑块外观

绘图选项

  • 符号颜色、形状、大小
  • 轴标签、变换
  • 工具提示(如悬停文本)
R 中级交互式数据可视化(plotly)

动画选项

使用默认设置的基础动画。

ani <- world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_markers(frame = ~year, 
              ids = ~country, 
              showlegend = FALSE) %>%
  layout(xaxis = list(type = "log"),
         yaxis = list(type = "log"))
R 中级交互式数据可视化(plotly)

动画选项

使用默认设置的基础动画。

ani %>%
  animation_opts(
      frame = 500, 
      transition = frame,
      easing = "linear",
      redraw = TRUE
   )
R 中级交互式数据可视化(plotly)

提速

使用 frame = 300 加速的散点图动画。

ani %>%
  animation_opts(frame = 300)
R 中级交互式数据可视化(plotly)

帧间暂停

每帧暂停 350 毫秒的动画。

ani %>%
  animation_opts(
     frame = 700, 
     transition = 350
  )
R 中级交互式数据可视化(plotly)

弹跳效果

使用 easing = "bounce" 的动画。

ani %>%
  animation_opts(easing = "bounce")

基础缓动选项:

"linear", "quad", "cubic", "sin", "exp", "circle", "elastic", "back", "bounce"

R 中级交互式数据可视化(plotly)

滑块选项

使用默认设置的基础动画。

ani
R 中级交互式数据可视化(plotly)

移除滑块

无滑块的动画。

ani %>%
  animation_slider(hide = TRUE)
R 中级交互式数据可视化(plotly)

编辑滑块文本

从滑块中移除前缀"year: "。

ani %>%
  animation_slider(
     currentvalue = list(prefix=NULL)
  )
R 中级交互式数据可视化(plotly)

编辑滑块文本

将滑块文本增大到 40 并改为黑色。

ani %>%
  animation_slider(
     currentvalue = list(prefix=NULL,
        font = list(
           color = "black", 
           size = 40
        )
     )
  )
R 中级交互式数据可视化(plotly)

Vamos praticar!

R 中级交互式数据可视化(plotly)

Preparing Video For Download...