【问题标题】:plotting multiple xts objects in one window在一个窗口中绘制多个 xts 对象
【发布时间】:2012-10-20 21:23:34
【问题描述】:

我在网上找到了一些答案,但由于某种原因我解释不正确,因为我无法让它工作。我的目标是简单地使用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 来做到这一点,但我想知道是否有办法一次性做到这一点。

【问题讨论】:

    标签: r plot xts zoo


    【解决方案1】:

    你可以强制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)
    

    【讨论】:

    • 在最新版本的xtsExtra 上,它警告xtsExtra::plot.xts 已弃用并使用xts::plot.xts,但xts::plot.xts 仍然无法处理多个时间序列,并且xtsExtra::plot.xts实际上并没有产生情节。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多