2012-10-20 28 views
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来做到这一点,但我想知道是否有办法一次完成。

回答

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

1

我可能是错的,但我认为plot.xts是不再是xtsExtra的一部分,并已移至主xt。 Source。也许这个笔记将帮助人们在未来试图找出在xts绘图..