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.xts doesn't plot more than 8 columns properly on `multi.panel = T` #423

Closed ethanbsmith closed 1 month ago

ethanbsmith commented 1 month ago

Description

when plotting more than 8 columns in multi.panel, the last columns dont display this is because plot.xts defaults col = 1:8

Expected behavior

default should handle any number of columns properly, either recycling the colors after 8, or defaulting col = 1:ncol(x)

Minimal, reproducible example

d <- xts(matrix(1:100, ncol = 10), order.by = Sys.Date() + (1:10))
plot(d, multi.panel = T)
plot(d, multi.panel = T, col = 1:ncol(d))

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  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8 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.1 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 1 month ago

This should be straightforward to fix. Want to give it a shot? It might be as easy as setting the default col = 1:nrow(x).

Is it also an issue for a single plot of an object with more than 8 columns?

ethanbsmith commented 1 month ago

multi.panel = F looks like it recycles col values. chart.lines handles recycling via: if(length(col) < NCOL(x)) col <- rep(col, length.out = NCOL(x))

I can work on a pr to move that check earlier in the flow