R-在一个窗口中绘制多个XTS对象



我在网上找到了一些答案,但由于某种原因,我无法正确地解释它,因为我无法使它起作用。我的目标是简单地使用xts绘图功能(使用其创建轴,网格线等的方式)来绘制多个图:

x <- xts(data.frame(a=1:100, b=100:1),seq(from=as.Date("2010-01-01"), by="days", len=100))
> plot(x, screens=1)
Warning messages:
1: In plot.xts(x, screens = 1) :
  only the univariate series will be plotted
2: In plot.window(...) : "screens" is not a graphical parameter
3: In plot.xy(xy, type, ...) : "screens" is not a graphical parameter
4: In axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) :
  "screens" is not a graphical parameter
5: In axis(1, at = xycoords$x[ep], labels = names(ep), las = 1, lwd = 1,  :
  "screens" is not a graphical parameter
6: In axis(2, ...) : "screens" is not a graphical parameter
7: In title(screens = 1) : "screens" is not a graphical parameter

另一次尝试:

> plot(x, plot.type="single")
Warning messages:
1: In plot.xts(x, plot.type = "single") :
   only the univariate series will be plotted
2: In plot.window(...) : "plot.type" is not a graphical parameter
3: In plot.xy(xy, type, ...) : "plot.type" is not a graphical parameter
4: In axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) :
  "plot.type" is not a graphical parameter
5: In axis(1, at = xycoords$x[ep], labels = names(ep), las = 1, lwd = 1,  :
  "plot.type" is not a graphical parameter
6: In axis(2, ...) : "plot.type" is not a graphical parameter
7: In title(plot.type = "single") :
  "plot.type" is not a graphical parameter

要清楚:我可以使用lines进行此操作,但是我想知道是否有一种方法可以立即完成。

您可以向zoo胁迫使用plot.zoo

plot(as.zoo(x), screens=1)
plot(as.zoo(x), plot.type='single')

或者,您可以安装具有较新的plot.xts方法

的XtSextra
#install.packages("xtsExtra", repos='http://r-forge.r-project.org')
library(xtsExtra)
plot(x, screens=1)

我可能是错误的,但我认为plot.xts不再是XtSextra的一部分,并且已移至主要XTS。来源。也许本说明将来会帮助人们尝试弄清楚XTS中的绘图。

最新更新