0

On one machine, plot.xts correctly displays data in two columns:

successful plot.xts

On another, things look very different:

failing plot.xts

The code for both is the same:

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)

The output of the successful machine:

> 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...

The output of the failing machine:

> 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...

The successful machine is local and the failing machine is remote with export DISPLAY=${IP}:0 to the successful machine.

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

kgibm
  • 852
  • 10
  • 22

3 Answers3

2

I was able to reproduce the different results using your script on the same machine - but using different versions of xtsExtra. The bad news is that the new version is giving the wrong result. This may be related to refactoring of xtsExtra/R/plot.R at r-forge.

Is it possible the package was installed more recently on the "failing machine"?

bergant
  • 7,122
  • 1
  • 20
  • 24
  • Hi, interesting! Yes, it was installed more recently on the "failing machine". Is there an older version I can download somewhere? – kgibm Feb 18 '15 at 15:57
  • Confirmed. I updated the "good machine" to the latest xtsExtra and now it's also broken: `install.packages("http://download.r-forge.r-project.org/src/contrib/xtsExtra_0.0-1.tar.gz", repos=NULL, type="source")` – kgibm Feb 18 '15 at 17:25
  • Opened bug https://r-forge.r-project.org/tracker/index.php?func=detail&aid=6029&group_id=118&atid=516 – kgibm Feb 18 '15 at 17:43
  • xtsExtra::plot.xts nor xts::plot.xts have arguments for `nc` and `yax.loc`. To plot multiple time series on different panels, see `?xts::plot.xts` and the `multi.panel` argument. You actually plotted the multiple time series on the same plot with the same y-axis although your data has very different ranges. That is why you see a line at the top and a line at the bottom of the chart. – RossB Feb 19 '15 at 14:22
  • I will look into changing the code to match the new API - `nc` and `yax.loc` used to exist in xtsExtra. – kgibm Feb 19 '15 at 16:05
2

As bergant mentioned in https://stackoverflow.com/a/28571442/1293660, this is a bug in xtsExtra. After a binary search, revision #850 is the latest version that works:

$ 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")
Community
  • 1
  • 1
kgibm
  • 852
  • 10
  • 22
1
plot.xts(data, main="Title", minor.ticks=FALSE, yax.loc="left", auto.grid=TRUE, nc=2)

see ?xts::plot.xts and you will note that there are not arguments for yax.loc or nc. The plot.xts code was refactored this past summer and now the development of plot.xts is happening in the xts package.

Install xts rev 875 from R-Forge and try the following, this worked for me.

plot.xts(data, main="Title", multi.panel=TRUE, minor.ticks=FALSE, yax.right=FALSE)
RossB
  • 111
  • 3
  • Hi Ross, both `yax.loc` and `nc` are in `?xtsExtra::plot.xts` in revision 850, so it seems there was a major change. I will review `multi.panel`... – kgibm Feb 19 '15 at 16:03
  • I checked out revision 875 and changed to the syntax above, and it's not working: http://stackoverflow.com/questions/28611858/r-xtsplot-xts-multi-panel-doesnt-produce-data – kgibm Feb 19 '15 at 16:39