4

I am trying to plot an xts object but I get an error about years.. The xts object just has a numerical value and a POSIXct index. Below is the code that shows the xts and the error when trying plot. Any ideas on what needs to be done to a xts object to properly plot?

xTest<-as.xts(35, Sys.time())
xTest
##                           [,1]
## 2013-04-07 18:19:19.37238   35
class(xTest)
## [1] "xts" "zoo"
class(index(xTest))
## [1] "POSIXct" "POSIXt"

plot(xTest)
##  Error in if (on == "years") { : missing value where TRUE/FALSE needed
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
Shinkaku
  • 41
  • 2

1 Answers1

4

What is your goal? Is there a problem that the plot.xts function will not plot fewer than 3 points? The error gets thrown by the xts::axTicksByTime because the minimum number of breaks is 2. Attempts to pass a different argument to axTicksByTime are frustrated by the coding in plot.xts which has no ... mechanism in it.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • I'm trying to plot trading data across multiple contracts that are not at consistent time intervals. The example provided was a simplification of the plot issue. Plotting just the date works without any issue as shown below. `>plot(index(xTest))` – Shinkaku Apr 09 '13 at 14:39