進階功能:強化你的圖表

案例研究:使用 R 的 Shiny 建置網頁應用程式

Dean Attali

Shiny Consultant

顏色輸入

library(colourpicker)

colourInput("col", "Select a colour", value = "orange")

chapter2_4_advanced_features_to_improve_your_plot.006.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

輸出可帶引數

plotOutput(outputId, width = "100%", height = "400px",
           click = NULL, dblclick = NULL, hover = NULL,
           hoverDelay = NULL, hoverDelayType = NULL, 
           brush = NULL, clickId = NULL, hoverId = NULL,
           inline = FALSE)
案例研究:使用 R 的 Shiny 建置網頁應用程式

圖表輸出引數

plotOutput("plot1", width = 200, height = 400)
plotOutput("plot2", width = 400, height = 200)

chapter2_4_advanced_features_to_improve_your_plot.008.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

使用 plotly 製作互動圖

  • 許多互動式繪圖套件
  • plotly 很常用
  • ggplotly()
    • ggplot2 圖表 ⇒ 互動式
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.015.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

使用 plotly 製作互動圖

  • 許多互動式繪圖套件
  • plotly 很常用
  • ggplotly()
    • ggplot2 圖表 ⇒ 互動式
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.016.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

使用 plotly 製作互動圖

  • 許多互動式繪圖套件
  • plotly 很常用
  • ggplotly()
    • ggplot2 圖表 ⇒ 互動式
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.017.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

使用 plotly 製作互動圖

  • 許多互動式繪圖套件
  • plotly 很常用
  • ggplotly()
    • ggplot2 圖表 ⇒ 互動式
p <- ggplot(gapminder, 
          aes(gdpPercap, lifeExp)) +
     geom_point() +
     scale_x_log10()

library(plotly)
ggplotly(p)

chapter2_4_advanced_features_to_improve_your_plot.018.png

案例研究:使用 R 的 Shiny 建置網頁應用程式

在 Shiny 使用 Plotly

  • 錯誤
plotOutput("plot")
renderPlot(ggplotly(p))
  • 正確
plotlyOutput("plot")
renderPlotly(ggplotly(p))
案例研究:使用 R 的 Shiny 建置網頁應用程式

一起來練習吧!

案例研究:使用 R 的 Shiny 建置網頁應用程式

Preparing Video For Download...