Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ethanbsmith opened this issue Jul 13, 2024 · 2 comments
Closed

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

ethanbsmith opened this issue Jul 13, 2024 · 2 comments
Milestone

Comments

@ethanbsmith
Copy link
Contributor

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
@ethanbsmith ethanbsmith changed the title plot fails on yaxis.same = T with only 1 non-na value plot fails on yaxis.same = F with only 1 non-na value Jul 13, 2024
@joshuaulrich
Copy link
Owner

joshuaulrich commented Jul 13, 2024

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.

@joshuaulrich joshuaulrich added this to the 0.14.1 milestone Jul 13, 2024
@ethanbsmith
Copy link
Contributor Author

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!!!!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 24, 2024
# xts 0.14.x (202x-xx-xx)

* `plot.xts()` now renders all panels when 'x' has more than 8 columns and
  `multi.panel = TRUE`. Columns 9 and later didn't render because the default
  of `plot.xts()` is 'col = 1:8'. Thanks to Ethan Smith for the report and
  patch.
  ([#423](joshuaulrich/xts#423))
  ([#424](joshuaulrich/xts#424))

* `plot.xts()` no longer errors when 'ylim' is constant and negative. Thanks
  to Ethan Smith for the report.
  ([#422](joshuaulrich/xts#422))

* Do not use `SET_TYPEOF()` in C because it is not part of the public R API.

* `merge.xts()` no longer converts 'x' or 'y' from double to integer in the C
  code when they are not used in the result. This avoids an unnecessary and
  confusing warning. Thanks to Jeff Ryan for the report.

# xts 0.14.0 (2024-06-05)

* `addEventLines()` and `addLegend()` now draw on multiple panels when `on` is
  a vector. Thanks to Ethan Smith for the report.
  ([#420](joshuaulrich/xts#420))

* Replace `SET_TYPEOF()` in merge.c because it will error when it tries to
  convert a REAL to an INTEGER. Thanks to Kurt Hornik for the report!
  ([#419](joshuaulrich/xts#419))

* Fix crash when 'j' is not an integer and in [0, 1) (e.g. `j = 0.1`). Also
  throw a warning when 'j' is not an integer.
  ([#413](joshuaulrich/xts#413))
  ([#415](joshuaulrich/xts#415))

* Fix plot header when `layout()` is used to draw multiple plots on a single
  device. Thanks to Dirk Eddelbuettel for the report and testing!
  ([#412](joshuaulrich/xts#412))

* Fix plot legend location when the y-axis is log scale.
  ([#407](joshuaulrich/xts#407))

# xts 0.13.2 (2024-01-21)

* Print a message when `period.apply()` is called with `FUN = mean` because it
  calculates the mean for each column, not all the data in the subset like it
  does for all other functions. The message says to use `FUN = colMeans` for
  current behavior and `FUN = function(x) mean(x)` to calculate the mean for
  all the data. This information is also included in the help files. The option
  `xts.message.period.apply.mean = FALSE` suppresses the message.
  ([#124](joshuaulrich/xts#124))

* Fix error when `print.xts()` is called 'quote' or 'right' arguments.
  ([#401](joshuaulrich/xts#401))

* Fix `addPolygon()` so it renders when `observation.based = TRUE`.
  ([#403](joshuaulrich/xts#403))

* Print trailing zeros for index value with fractional seconds, so every index
  value has the same number of characters.
  ([#404](joshuaulrich/xts#404))

* Add ability to log scale the y-axis in `plot.xts()`.
  ([#103](joshuaulrich/xts#103))

* Actually change the underlying index values when 'tclass' is changed from a
  class with a timezone (e.g. POSIXct) to one without a timezone (e.g. Date).
  Add a warning when this happens, with a global option to always suppress the
  warning.
  ([#311](joshuaulrich/xts#311)).

* Significantly refactor the internals of `plot.xts()`.
  ([#408](joshuaulrich/xts#408))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants