潤飾動畫

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 互動式資料視覺化:中級

一起來練習吧!

R 的 plotly 互動式資料視覺化:中級

Preparing Video For Download...