plotting multiple xts objects in one window

╄→гoц情女王★ 提交于 2019-12-06 02:51:22

问题


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

Another try:

> 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

To be clear: I can do this using lines but I wonder if there is a way to do this all at once.


回答1:


You could coerce to zoo to use plot.zoo:

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

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)



回答2:


I could be wrong but I think plot.xts is no longer part of xtsExtra and has moved to the main xts. Source. Maybe this note will help people in the future trying to figure out plotting in xts..



来源:https://stackoverflow.com/questions/12992831/plotting-multiple-xts-objects-in-one-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!