Open cloudcell opened 8 years ago
cloudcello, thank you for the reproducible example. From the ?plot.xts
and the multi.panel
argument,
For example, if multi.panel = 2, then the data will be plotted in groups of 2 columns and each group is plotted in a separate panel.
In your example, calling plot.xts
with multi.panel=2
is actually creating 15 plot windows with 2 panels in each window. Also explained in the documentation, on
is not an argument for plot.xts
, it is an argument for lines.xts
and points.xts
.
This should produce the plot you are looking for
plot(PL.xts, col=c("blue", rep("grey", n-1)), main="Walk Forward Analysis")
# set on=NA so it is drawn on a new panel
lines(Drawdowns.xts, col=c("blue", rep("grey", n-1)), on=NA, main="Drawdowns")
I think we may have a bug with multi.panel
behavior that I need to explore further.
Thank you for the solution, Ross. I definitely missed that option ("on=NA") while reading help. Also, I'm glad this has been helpful. Just one more comment: I think the code must nevertheless be as follows (as the total number of lines drawn is not n, but rather n+1:
plot(PL.xts, col=c("blue", rep("grey", n)), main="Walk Forward Analysis")
# set on=NA so it is drawn on a new panel
lines(Drawdowns.xts, col=c("blue", rep("grey", n)), on=NA, main="Drawdowns")
This code was extracted (with minor modifications/additions) from
quantstrat::chart.forward.training
and based on the data supplied withdemo(luxor.sample.walk.forward)
, using R 3.2.2 on Windows 7.