Milktrader
Milktrader

Reputation: 9858

Can't get multiple panel plots with chartSeries function from quantod package in R

Jeff Ryan's quantmod package is an excellent contribution to the R finance world.

I like to use chartSeries() function, but when I try to get it to display multiple panes simultaneously, it doesn't work.

par(mfrow=c(2,2))

chartSeries (SPX)
chartSeries (SPX, subset="2010")

chartSeries (NDX)
chartSeries (NDX, subset="2010")

would normally return a four-panel graphic as it does with the plot() function but in the chartSeries example it runs through all instances one at a time without creating a single four-panel graphic.

Upvotes: 3

Views: 2872

Answers (3)

algoquant
algoquant

Reputation: 1127

I will just add to Brian G. Peterson's post a working quantmod code example for creating chart_Series plots in multiple panels:

# download data and copy it into environment
sym_bols <- c("IEF", "VTI", "XLP", "XLF", "XLK", "VXX")
data_env <- new.env()
quantmod::getSymbols(sym_bols, env=data_env, from="2017-01-01")
# create chart_Series plots in multiple panels
x11()
par(mfrow=c(3, 2))
par(mar=c(2, 2, 2, 1), oma=c(0, 0, 0, 0))
eapply(data_env, function(x) {
  plot(quantmod::chart_Series(x["2017-06/"], 
       name=strsplit(colnames(x)[1], split="[.]")[[1]][1]))
})  # end eapply

Note that chart_Series must be wrapped in plot.

Produces the following plot:

enter image description here

Upvotes: 0

Brian G. Peterson
Brian G. Peterson

Reputation: 66

use chart_Series() instead of chartSeries() it is layout() and par() compliant.

Upvotes: 5

Dirk is no longer here
Dirk is no longer here

Reputation: 368539

No, sadly, you cannot (unless this changed very recently).

The power of adding new sub-panels comes at the prices of not being able to combine these plots as you otherwise could in base graphics.

But you could re-create them in base graphics and then the par(mfrow=...) etc idioms would be available to you.

Upvotes: 0

Related Questions