You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
plot.xts seems to have an issue at determining the ylim range when a timeseries has constant value for its entire duration.
Here is a reproducible example:
data=rep(100, 23); #23 observation with value 100
index=seq(as.POSIXlt("2016-06-01 01:00"), as.POSIXlt("2016-06-01 23:00"), by="60 min"); # 23 timestamps spaced hourly
data.xts<-xts(data,index);
plot(data.xts);
which results in:
Error in segments(xlim[1], y_grid_lines(get_ylim()[[2]]), xlim[2], y_grid_lines(get_ylim()[[2]]), :
cannot mix zero-length and non-zero-length coordinates
Setting the ylim manually with plot(data.xts, ylim=c(0,110)) prevents the error from happening.
I am using the last xts version from git-hub (cloned last week).
The text was updated successfully, but these errors were encountered:
plot.xts() would error if called on an object with a series of one
constant value (e.g. .xts(rep(1,10), 1:10)) because the y-coordinates
are the same.
Create different y-coordinates that are +/-20% from the series value.
Also move the check for all ylim equal to zero outside of the if/else
block. This avoids code duplication, and therefore potential future
bugs.
Fixes#156.
I am attempting to use `plot.xts` to plot a series which contains constant values, however I encounter the error
> Error in segments(xlim[1], y_grid_lines(get_ylim()[[2]]), xlim[2], y_grid_lines(get_ylim()[[2]]), :
> cannot mix zero-length and non-zero-length coordinates
After a little Googling, I was puzzled to see that this issue was fixed in joshuaulrich#156
With the help of `debug` I found that in my case, numerical precision issues we're causing my data to side step the check. The difference can only be seen with `sprintf`. Debug console output
```
Debug> yrange <- range(cs$Env$xdata[, 1][subset], na.rm = TRUE)
Debug> dput(yrange)
c(6e+05, 6e+05)
Debug> yrange[1L] == yrange[2L]
[1] FALSE
Debug> sprintf("%.6f", yrange[[1]])
[1] "600000.000000"
Debug> sprintf("%.9f", yrange[[1]])
[1] "600000.000000000"
Debug> sprintf("%.12f", yrange[[1]])
[1] "599999.999999999767"
Debug> sprintf("%.12f", yrange[[2]])
[1] "600000.000000000116"
Debug> isTRUE(all.equal(yrange[1], yrange[2]))
[1] TRUE
```
Proposal is to replace the strict `==` check, with `all.equal`, which includes a tolerance of `tolerance=sqrt(.Machine$double.eps)`
Thanks
plot.xts seems to have an issue at determining the ylim range when a timeseries has constant value for its entire duration.
Here is a reproducible example:
which results in:
Setting the ylim manually with plot(data.xts, ylim=c(0,110)) prevents the error from happening.
I am using the last xts version from git-hub (cloned last week).
The text was updated successfully, but these errors were encountered: