本文介绍了在一个窗口中绘制多个 xts 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网上找到了一些答案,但由于某种原因我的解释不正确,因为我无法让它工作.我的目标是简单地使用 xts
绘图功能(使用它创建轴、网格线等的方式)来绘制多个图:
I have found some answers to this online but for some reason am interpreting incorrectly because I cannot get it to work. My goal is to simply use the xts
plotting feature (with the the way it creates the axis, gridlines,etc.) to plot multiple plots:
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
来做到这一点,但我想知道是否有办法一次性做到这一点.
To be clear: I can do this using lines
but I wonder if there is a way to do this all at once.
推荐答案
你可以强制zoo
使用plot.zoo
:
plot(as.zoo(x), screens=1)
plot(as.zoo(x), plot.type='single')
或者,您可以安装 xtsExtra ,它具有更新的 plot.xts 方法
Or, you could install xtsExtra which has a newer plot.xts
method
#install.packages("xtsExtra", repos='http://r-forge.r-project.org')
library(xtsExtra)
plot(x, screens=1)
这篇关于在一个窗口中绘制多个 xts 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!