Forum: open-discussion
Monitor Forum | | RE: Bug in make.par.list? [ Reply ] By: Achim Zeileis on 2026-01-07 20:38 | [forum:50144] |
|
Ah, this is a good point, now I understand. Yes, indeed, unnaming the colors is necessary in this case. (The same is true in ggplot2 by the way). Best wishes, Achim |
|
| RE: Bug in make.par.list? [ Reply ] By: Simone Giannerini on 2026-01-07 19:47 | [forum:50143] |
|
Dear Achim, many thanks for the clarification, yes you are right that the behaviour is intended. I was erroneously thinking that the arguments are matched positionally as in ts.plot. Just to add some context as to why, I defined a new color using rgb and use it in plot.zoo library(zoo) rval <- col2rgb('blue') bluet <- rgb(red=rval[1], green=rval[2], blue=rval[3], alpha=100, names = "bluet", maxColorValue = 255) # adds transparency to blue x <- zoo(matrix(1:6,3,2)) plot.zoo(x,col=c(bluet,'orange'),type='b',plot.type='single') # NOT OK ts.plot(x,col=c(bluet,'orange'),type='b') # OK now I realize that in order to be used with plot.zoo, bluet has to be unnamed plot.zoo(x,col=c(unname(bluet),'orange'),type='b',plot.type='single') # OK Many thanks again and sorry for the noise. Simone |
|
| RE: Bug in make.par.list? [ Reply ] By: Achim Zeileis on 2026-01-07 00:37 | [forum:50142] |
|
Simone, to me this all looks as intended. What would you have expected? The idea for the partially named arguments is the following. You can facilitate setting a color for one column (deeppink2 for the DAX series in the example below) and use another default color for everything else (slategray in the example below): plot(as.zoo(EuStockMarkets), col = c(DAX = "deeppink2", "slategray"), plot.type = "single") So in your example you have two columns/series V1 and V2, respectively. If you specify two colors without names as col=c('blue','orange'), then these are matched positionally as you expect. If you specify col=c(blue='blue','orange') this is interpreted as: Use the color 'blue' for the column blue (which does not exist) and the color 'orange' for everything else. If you specify col=c(blue='blue',orange='orange') then this is interpreted as specifying colors for the columns blue and orange which both do not exist. Thus, the function has to resort to the default color 1 for all columns. See Section 2.3 in vignette("zoo", package = "zoo") for a few further examples and explanations. |
|
| Bug in make.par.list? [ Reply ] By: Simone Giannerini on 2025-12-28 18:50 | [forum:50141] |
|
Dear all, I noticed a (strange?) behaviour of plot.zoo that can be traced down to make.par.list when the arguments are (partially) named, please see the following MRE. > x <- zoo(matrix(1:6,3,2)) > cnx <- c('V1','V2') > colnames(x) <- cnx > > plot.zoo(x,col=c('blue','orange'),type='b') # OK > plot.zoo(x,col=c(blue='blue','orange'),type='b') # NOT OK > plot.zoo(x,col=c(blue='blue',orange='orange'),type='b') # NOT OK > > make.par.list(cnx, c('blue','orange'), NROW(x), NCOL(x), 1) $V1 [1] "blue" $V2 [1] "orange" > make.par.list(cnx, c(blue='blue','orange'), NROW(x), NCOL(x), 1) $V1 [1] "orange" $V2 [1] "orange" > make.par.list(cnx, c(blue='blue',orange='orange'), NROW(x), NCOL(x), 1) $V1 [1] 1 $V2 [1] 1 It is not clear to me from the docs whether this is expected. Thank you. Simone |
|

