为什么 R xts plot 只显示一个 nc=2 的列?

Why does R xts plot only show a single column with nc=2?

在一台机器上,plot.xts 正确显示两列数据:

另一方面,情况看起来非常不同:

两者的代码相同:

library(zoo)
library(xts)
library(xtsExtra)
sessionInfo()
timezone = "UTC"
Sys.setenv(TZ=timezone)
sampleData = "Time (UTC),CPU,Runqueue,Blocked,MemoryFree,PageIns,ContextSwitches,Wait,Steal
2014-10-15 16:12:11,20,0,0,12222172,0,2549,0,0
2014-10-15 16:12:12,27,1,0,12220732,0,3619,0,0
2014-10-15 16:12:13,30,0,0,12220212,0,2316,0,0"
data = as.xts(read.zoo(text=sampleData, format="%Y-%m-%d %H:%M:%S", header=TRUE, sep=",", tz=timezone))
plot.xts(data, main="Title", minor.ticks=FALSE, yax.loc="left", auto.grid=TRUE, nc=2)

成功机的输出:

> library(zoo)

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

> library(xts)
> library(xtsExtra)

Attaching package: ‘xtsExtra’

The following object is masked from ‘package:xts’:

    plot.xts

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xtsExtra_0.0-1 xts_0.9-7      zoo_1.7-11    

loaded via a namespace (and not attached):
[1] grid_3.1.2      lattice_0.20-29
... The rest are just commands, no warnings/errors...

故障机器的输出:

> library(zoo)

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

> library(xts)
> library(xtsExtra)

Attaching package: 'xtsExtra'

The following object is masked from 'package:xts':

    plot.xts

> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets    methods   base     

other attached packages:
[1] xtsExtra_0.0-1 xts_0.9-7      zoo_1.7-11    

loaded via a namespace (and not attached):
    [1] grid_3.1.2      lattice_0.20-29
... The rest are just commands, no warnings/errors...

成功的机器是本地的,失败的机器是远程的 export DISPLAY=${IP}:0 到成功的机器。

为什么 R xts 图只显示 nc=2 的单列?

我能够在 同一台机器 上使用您的脚本重现不同的结果 - 但使用 不同版本的 xtsExtra。坏消息是新版本给出了错误的结果。这可能与 xtsExtra/R/plot.R 在 r-forge 处的重构有关。

是否有可能最近在 "failing machine" 上安装了软件包?

正如 bergant 在 中提到的,这是 xtsExtra 中的一个错误。经过二进制搜索,修订版 #850 是最新版本:

$ svn checkout --revision 850 svn://svn.r-forge.r-project.org/svnroot/xts/
$ R
> install.packages("xts/pkg/xts", repos=NULL, type="source")
> install.packages("xts/pkg/xtsExtra", repos=NULL, type="source")
plot.xts(data, main="Title", minor.ticks=FALSE, yax.loc="left", auto.grid=TRUE, nc=2)

请参阅 ?xts::plot.xts,您会注意到 yax.locnc 没有参数。 plot.xts 代码在去年夏天进行了重构,现在 plot.xts 的开发正在 xts 包中进行。

从 R-Forge 安装 xts rev 875 并尝试以下操作,这对我有用。

plot.xts(data, main="Title", multi.panel=TRUE, minor.ticks=FALSE, yax.right=FALSE)