2015-02-17 77 views
0

在一臺機器,在兩列plot.xts正確顯示數據:爲什麼R xts圖只顯示nc = 2的單個列?

successful plot.xts

在另一個,事情看起來非常不同:

failing 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的單列?

回答

2

由於https://stackoverflow.com/a/28571442/1293660中提到的原因,這是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") 
2

我能夠重現使用同一臺機器上腳本中的不同的結果 - 但使用不同版本xtsExtra的。壞消息是新版本給出了錯誤的結果。這可能與重構xtsExtra/R/plot.R在r-forge有關。

包是最近安裝在「失敗的機器」上嗎?

+0

嗨,有趣!是的,它最近安裝在「失敗的機器」上。是否有舊版本可以下載? – kgibm 2015-02-18 15:57:12

+0

確認。我更新了「好機器」到最新的xtsExtra,現在它也壞了:'install.packages(「http://download.r-forge.r-project.org/src/contrib/xtsExtra_0.0-1.tar .gz「,repos = NULL,type =」source「)' – kgibm 2015-02-18 17:25:48

+0

已打開的bug https://r-forge.r-project.org/tracker/index.php?func=detail&aid=6029&group_id=118&atid=516 – kgibm 2015-02-18 17:43:44

1
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) 
+0

嗨Ross,'yax.loc'和'nc'都在'?xtsExtra :: plot。xts'版本850,所以它似乎有一個重大變化。我將審查'multi.panel' ... – kgibm 2015-02-19 16:03:25

+0

我檢出了修訂版875並更改爲上面的語法,它不工作:http://stackoverflow.com/questions/28611858/r-xtsplot-xts-multi-panel -doesnt-產生數據 – kgibm 2015-02-19 16:39:48