開始使用免費開始

加入時間滑桿

在上一個課程中,你建立了一個動畫,用來顯示各州在各年發射次數。滑桿是動畫的替代方案,能讓你完全掌控要探索的時間區段。例如,你可以從頭看到尾,或只聚焦在 1960 年代。本練習要你在以州為單位的發射次數折線圖下方加入一個滑桿。

plotlycrosstalkdplyr,以及 state_launches 資料集都已為你載入。

本練習屬於課程

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

檢視課程

練習說明

  • state_codelaunch_year 計算發射次數,並將結果轉成 SharedData 物件。將結果存成 shared_launches
  • 使用 shared_launches 建立折線圖,顯示各州隨時間變化的發射次數(n)。將此圖存為 launch_ts。用顏色表示 state_code
  • 在圖表下方放置一個滑桿來篩選顯示的年份。將此滑桿標示為 "Year"

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a SharedData object containing the number of launches by year and state
shared_launches <- state_launches %>%
  count(___, ___) %>%
  ___()

# Create a line chart displaying the launches by state
launch_ts <- ___ %>%
  ___(x = ___, y = ___, color = ___) %>%
  ___()  

# Add a slider below the chart to filter the years displayed
___(list(___,
    ___(id = "time", label = ___, 
        sharedData = ___, column = ___)
))
編輯並執行程式碼