在一个窗口中绘制多个xts对象

5
我在网上找到了一些答案,但由于我解释错误,所以无法使其正常工作。我的目标是简单地使用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可以实现这一点,但我想知道是否有一种一次性完成所有操作的方法。

2个回答

9
您可以强制将zoo转化为使用plot.zoo
plot(as.zoo(x), screens=1)
plot(as.zoo(x), plot.type='single')

或者,您可以安装xtsExtra,该软件具有更新的plot.xts方法。

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

6
在最新版本的xtsExtra中,它警告说xtsExtra::plot.xts已被弃用,应该使用xts::plot.xts,但是xts::plot.xts仍然无法处理多个时间序列,而xtsExtra::plot.xts实际上不会生成绘图。 - tchakravarty

2
我可能错了,但我认为plot.xts不再是xtsExtra的一部分,而是已经移动到主要的xts中。来源。也许这个注释将帮助未来尝试在xts中绘图的人们。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接