1

I get an error "Error in if (on == "years") { (from #17) : missing value where TRUE/FALSE needed" when trying to plot sub-second series in xts. That is, my xts object only includes observations for the same second:

                         value
2013-04-23 13:09:29.0000 471295
2013-04-23 13:09:29.0000 471296
2013-04-23 13:09:29.0002 471297
2013-04-23 13:09:29.0002 471298
2013-04-23 13:09:29.0004 471299
2013-04-23 13:09:29.0004 471300
2013-04-23 13:09:29.0006 471295

A similar question about this error was already asked in this thread but I'm not clear if there is a workaround to plot sub-second series.

Community
  • 1
  • 1
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91

2 Answers2

3
R> zzz <- xts(100+cumsum(rnorm(10)), Sys.time() + cumsum(runif(10))/1e3)
R> zzz
                               [,1]
2013-04-30 10:15:15.588007  98.9827
2013-04-30 10:15:15.588615 100.0029
2013-04-30 10:15:15.589559 100.6558
2013-04-30 10:15:15.590063  98.7353
2013-04-30 10:15:15.590466 100.0204
2013-04-30 10:15:15.590787 100.5416
2013-04-30 10:15:15.591345 100.5990
2013-04-30 10:15:15.591624 100.7908
2013-04-30 10:15:15.592415 101.8566
2013-04-30 10:15:15.592915 102.4576
R> plot(zzz)
Error in if (on == "years") { : missing value where TRUE/FALSE needed
R> traceback()
4: endpoints(x, cl, ck)
3: axTicksByTime(x, major.ticks, format.labels = major.format)
2: plot.xts(zzz)
1: plot(zzz)
R> 

So the error comes from the axis formatting. You can either override this, suppress it by now asking for axis to be drawn or just do

R> plot(as.zoo(zzz))

which works fine as your series is univariate anyway.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
1

This is essentially the same issue as in this post. A solution is to specify major.ticks

> set.seed(1)
> zzz <- xts(100+cumsum(rnorm(10)), .POSIXct(0) + cumsum(runif(10))/1e3)
> plot(zzz, major.ticks="seconds")

enter image description here

Community
  • 1
  • 1
GSee
  • 48,880
  • 13
  • 125
  • 145
  • I actually use `plot.zoo` waaaay more than `plot.xts`. `plot.xts` from the [xtsExtra](https://r-forge.r-project.org/R/?group_id=118) package is really cool, but it's less developed/less stable than `plot.zoo`. – GSee Apr 30 '13 at 16:30