简体   繁体   English

R:quantmod,chartseries和PDF

[英]R: quantmod, chartseries and PDF

What is the best way to graph 8 charts at once using quantmod? 使用Quantmod一次绘制8个图表的最佳方法是什么?

Here are some options: 以下是一些选项:
1. collate all 8 charts in memory, then combine into a 8.5" x 11" pdf 1.整理内存中的所有8个图表,然后合并成8.5“ x 11” pdf
2. save each chart as a png, then combine into a pdf 2.将每个图表另存为png,然后合并为pdf

I would prefer option #1 to #2. 我宁愿选择#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')")
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()

screenshots of the pdf pdf的屏幕截图

Completely zoomed out 完全缩小

在此处输入图片说明

a bit closer 靠近一点

在此处输入图片说明

UPDATE UPDATE

You can use chart_Series() , shich respects the settings in par() . 您可以使用chart_Series() ,尊重par()的设置。 But I am not getting the arguments right, so the charts do not look as nice as with chartSeries . 但是我的参数不正确,因此图表看起来不如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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM