0

I have an xts/zoo object ESZ1:

> class(ESZ1) 
[1] "xts" "zoo"

with

> class(time(ESZ1))
[1] "POSIXt"  "POSIXct"

and

> colnames(ESZ1)
[1] "ESZ1.Open"    "ESZ1.High"    "ESZ1.Low"     "ESZ1.Close"   "ESZ1.Volume"  "ESZ1.WAP"     "ESZ1.hasGaps" "ESZ1.Count"  

and I would like to plot it using the chartSeries function from the package quantmod. However, I get the following error:

> chartSeries(ESZ1)
Error in if (on == "years") { : missing value where TRUE/FALSE needed

Any ideas of what the problem could be would be greatly appreciated.

Additional question: Is there any documentation for how to adjust the axes/margins for chartSeries()? Currently my y-axis labels are partially cut off on the right-hand margin of the plot. I've tried using

mar = ...

in the argument list of chartSeries, but this did not change the resulting plot.

Ethan B
  • 1
  • 1
  • 2

2 Answers2

3

The issue is within chartSeries, specifically the axTicksByTime call. I'll add a patch to fix this, but for now you can do:

chartSeries(ESZ1, major.ticks="minutes")

By default major.ticks="auto" and it seems to fail too early in the automagical procedure to get to the right answer.

Jeff R
  • 829
  • 4
  • 5
  • 1
    Thanks that worked for me. Note that it's March 2013 and I'm using the latest versions. Maybe the origin of my problem is different? I have daily data, but major.ticks="minutes" helped, despite the absence of minutes data. I don't have the problem for a truncated version of the same dataset. – PatrickT Mar 27 '13 at 20:52
2

You have not provided enough information about your ESZ1 object, but I can reproduce the error by trying to plot 2 minutes or less of data. Your column names look like something from IBrokers,so ...

> library(IBrokers)
> library(quantmod)
> ibg <- ibgConnect()
> fut <- twsFUT('ES', 'GLOBEX', '201112')
> ESZ1 <- reqHistoricalData(ibg, fut, barSize='1 secs', duration='120 S')
TWS Message: 2 -1 2104 Market data farm connection is OK:usfuture 
TWS Message: 2 -1 2106 HMDS data farm connection is OK:ushmds2a 
waiting for TWS reply on ES .... done.
> chartSeries(ESZ1)
Error in if (on == "years") { : missing value where TRUE/FALSE needed

If you use more than 2 minutes of data it works.

> ESZ1 <- reqHistoricalData(ibg, fut, barSize='1 secs', duration='121 S')
waiting for TWS reply on ES .... done.
> chartSeries(ESZ1)

> indexClass(ESZ1)
[1] "POSIXct" "POSIXt" 
> colnames(ESZ1)
[1] "ESZ1.Open"    "ESZ1.High"    "ESZ1.Low"     "ESZ1.Close"   "ESZ1.Volume" 
[6] "ESZ1.WAP"     "ESZ1.hasGaps" "ESZ1.Count"  
GSee
  • 48,880
  • 13
  • 125
  • 145
  • My apologies for not providing a reproducible example, but yes, you correctly gathered that I was using IBrokers to import data. And yes, I was trying to plot only 1 minute of data consisting of 1-second bars. Is that not possible? I'll try and see if it will work for me with more than 2 minutes of data. – Ethan B Nov 02 '11 at 15:30