神刀安全网

R-Markdown and Knitr Tutorial (Part 1)

Inserting a Plotly graph

Inserting an awesome interactive Plotly chart is as simple as printing out the plotly object in a code chunk. Use the code snippet below.

source("Yahoo Stock Data Pull.R")  AAPL <-  GetYahooData("AAPL") IBM <- GetYahooData("IBM")  # Plotly chart  library(plotly) mat <-  data.frame(Date = AAPL$Date,                     AAPL = round(AAPL$Adj.Close,2),                    IBM = round(IBM$Adj.Close,2))  p <- mat %>%    plot_ly(x = Date, y = AAPL, fill = "tozeroy", name = "Microsoft") %>%    add_trace(y = IBM, fill = "tonexty", name = "IBM") %>%    layout(title = "Stock Prices",           xaxis = list(title = "Time"),          yaxis = list(title = "Stock Prices")) p  # Thats it !

原文  http://www.r-bloggers.com/r-markdown-and-knitr-tutorial-part-1/

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » R-Markdown and Knitr Tutorial (Part 1)

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮