joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

plot fails on `yaxis.same = F` with only 1 non-na value #422

Closed ethanbsmith closed 2 months ago

ethanbsmith commented 2 months ago

Minimal, reproducible example

z <- xts(cbind(1:10, rep(NA_real_, 10)), order.by = Sys.Date() + (1:10))
z[5,2] <- -3
plot(z, multi.panel = T) #works fine
plot(z, multi.panel = T, yaxis.same = F) # <- error
#Error in segments(x0 = xlim[1], y0 = grid_loc, x1 = xlim[2], y1 = grid_loc,  : 
#  cannot mix zero-length and non-zero-length coordinates

z[3,2] <- -5 #add a second non-na value
plot(z, multi.panel = T, yaxis.same = F) #works fine

Session Info

R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Denver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xts_0.14.0 zoo_1.8-12

loaded via a namespace (and not attached):
[1] compiler_4.4.0 grid_4.4.0     lattice_0.22-6
joshuaulrich commented 2 months ago

Thanks for the report and example!

This happens in create_ylim() when the min/max are the same and negative. This throws the same error:

require(xts)
z <- xts(cbind(1:10, rep(NA_real_, 10)), order.by = Sys.Date() + (1:10))
z[,2] <- -3
plot(z, multi.panel = T, yaxis.same = F)

Please test the branch I just pushed on your actual use case.

ethanbsmith commented 2 months ago

damn, u fixed that faster than the time it took me to remember the toolchain setup i needed to start work on a fix. branch works great. Thx!!!!