R:quantmod,chartseries和PDF

时间:2018-04-16 06:07:09

标签: r png quantmod

使用quantmod一次绘制8个图表的最佳方法是什么?

以下是一些选项:
1。整理内存中的所有8个图表,然后组合成8.5“x 11”pdf
2。将每个图表保存为png,然后合并为pdf

我更喜欢选项#1到#2。

library(tidyverse)
library(quantmod)
s = c("AAL","DAL","UAL","LUV","FDX","ALK","JBLU","HA")

# example of charts to graph
getSymbols("AAL", src="yahoo")
chartSeries(AAL, type="line",subset='last 60 months',
  TA="addSMA(200,col='orange');addSMA(65,col='red')")
getSymbols("DAL", src="yahoo")
chartSeries(DAL, type="line",subset='last 60 months',
  TA="addSMA(200,col='orange');addSMA(65,col='red')")

1 个答案:

答案 0 :(得分:3)

library(quantmod)
s = c("AAL","DAL","UAL","LUV","FDX","ALK","JBLU","HA")

symbols <- list (getSymbols(s, source = "yahoo"))

pdf(file = "charts.pdf")
par(mfrow = c( 8, 1 ) )
chartSeries(AAL, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(DAL, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(UAL, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(LUV, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(FDX, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(ALK, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(JBLU, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
chartSeries(HA, type="line",subset='last 60 months', TA="addSMA(200,col='orange');addSMA(65,col='red')")
dev.off()

pdf屏幕截图

完全缩小

enter image description here

近一点

enter image description here

更新

您可以使用chart_Series(),但应遵守par()中的设置。但是我的论点不正确,因此图表看起来不如chartSeries好。

pdf(file = "charts.pdf")
par(mfrow = c( 4, 2 ) )
chart_Series(AAL)
chart_Series(DAL)
chart_Series(UAL)
chart_Series(LUV)
chart_Series(FDX)
chart_Series(ALK)
chart_Series(JBLU)
chart_Series(HA)
dev.off()

enter image description here