為圖表加上標籤

使用 R 的 plotly 互動式資料視覺化

Adam Loy

Statistician, Carleton College

23_default_scatter.gif

使用 R 的 plotly 互動式資料視覺化

23_default_bar.gif

使用 R 的 plotly 互動式資料視覺化

23_default_box.gif

使用 R 的 plotly 互動式資料視覺化

變更預設顯示

 wine %>%
  count(Type) %>%  
  plot_ly(x = ~Type, y = ~n,
      # Changing the default info displayed
          hoverinfo = "y" 
  ) %>%
  add_bars()

hoverinfo =

  • "all"
  • "x"
  • "y"
  • "x+y"
  • "x+y+z"
使用 R 的 plotly 互動式資料視覺化

自訂滑過文字

wine %>%
  plot_ly(x = ~Flavanoids, y = ~Alcohol,

hoverinfo = "text",
text = ~paste("Flavanoids:", Flavanoids, "<br>", "Alcohol:", Alcohol)
) %>% add_markers()
  • 波浪號 ~:將欄位對應到視覺參數

使用 R 的 plotly 互動式資料視覺化

一起來練習吧!

使用 R 的 plotly 互動式資料視覺化

Preparing Video For Download...