Quantmod多个图表在一个pdf中

时间:2018-06-08 18:46:17

标签: r function pdf charts quantmod

我想在quantmod中绘制两个图表,然后将它们放在一个pdf中如何实现这一目标?下面的代码示例,在此代码中,我生成两个单独的pdf但如何将它们合并到一个文件中?

  getSymbols("AAPL", src = "yahoo", from = start, to = end)
  getSymbols("GOOGL", src = "yahoo", from = start, to = end)


  candleChart(AAPL, multi.col=TRUE, theme='white') 
  addMACD()
  dev.copy(pdf, "chart1.pdf")

  candleChart(GOOGL, multi.col=TRUE, theme='white') 
  dev.copy(pdf, "chart2.pdf")
  dev.off()

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你可以这样做:

start = "2018-01-01"
end = "2018-04-01"
getSymbols("AAPL", src = "yahoo", from = start, to = end)
getSymbols("GOOGL", src = "yahoo", from = start, to = end)


pdf(file = "charts.pdf")
par(mfrow=c(2,1))
chart_Series(AAPL, TA = "add_MACD();") 
chart_Series(GOOGL) 
dev.off()