開始使用免費開始

加入滑桿

滑桿篩選器可以透過限制數值變數的範圍,輕鬆更新圖上所繪製的資料值。在這個練習中,你要為 2017 年房價指數與自有住房率的散佈圖新增兩個滑桿篩選器:各軸各一個。

已為你載入 plotlycrosstalk,資料存於 us2017

注意:你可能需要向下捲動或將 HTML 檢視器彈出,才能看到滑桿。

本練習屬於課程

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

檢視課程

練習說明

  • 在儲存在 p17 的散佈圖下方放置兩個滑桿篩選器。第一個滑桿應對應房價指數(house_price),第二個滑桿應對應自有住房率百分比(home_owners)。
  • 新增與 p17 軸標題相符的滑桿標籤:"HPI""Home ownership (%)"

動手互動練習

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

shared_us <- SharedData$new(us2017)
p17 <- shared_us %>%
  plot_ly(x = ~home_owners, y = ~house_price, 
          color = ~region, height = 400) %>%
  add_markers() %>%
  layout(xaxis = list(title = "Home ownership (%)"), 
         yaxis = list(title = "HPI"))
  
# add a slider filter for each axis below the scatterplot
___(
  ___(p17,
      ___(id = "price",  label = ___,  sharedData = ___,  column = ___),
      ___(id = "owners",  label = ___,  sharedData = ___, column = ___)
  )
)
編輯並執行程式碼