In several places, we have the convention that col = NA means `` don't draw '', e.g. for points() or rect(). For col = <vector> this only works when the vector is integer (numeric), but not in other cases. I think this is a bug, even though not in the strict sense, since we don't seem to claim it should work.. Example: plot(1:10, col = c(1:4,NA,NA,4:1)) ## fine (cc <- heat.colors(4)) plot(1:10, col = c(cc, NA,NA,rev(cc))) ## gives error : Error in plot.xy(xy, type, col = col, pch = pch, cex = cex, bg = bg, lty = lty, : invalid color name ------- Does anybody see a problem in making "NA" for character colors behave the same as NA for integer (numeric) ones ? Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Martin Maechler
2001-Jul-10 17:09 UTC
[Rd] segments(*, col = c(..,NA,..)) {was "color NA ..."}
>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:MM> In several places, we have the convention that col = NA means `` MM> don't draw '', e.g. for points() or rect(). MM> For col = <vector> this only works when the vector is integer MM> (numeric), but not in other cases. I think this is a bug, even MM> though not in the strict sense, since we don't seem to claim it MM> should work.. MM> Example: MM> plot(1:10, col = c(1:4,NA,NA,4:1)) MM> ## fine MM> (cc <- heat.colors(4)) plot(1:10, col = c(cc, NA,NA,rev(cc))) MM> ## gives error : MM> Error in plot.xy(xy, type, col = col, pch = pch, cex = cex, bg MM> bg, lty = lty, : invalid color name MM> ------- MM> Does anybody see a problem in making "NA" for character colors MM> behave the same as NA for integer (numeric) ones ? And I have the patch ready (tested and documented) for this, to be committed to "R-patched" i.e. to be in 1.3.1, unless .... Note however the following `misbehavior' (I think) of segments() : n <- 8 x <- 1:n ep <- 0.2 cc <- c(1:4,NA,6:n) plot(x, col= cc, type='h') points(x, col= cc, cex=2) segments(x+ep, x[1], x+ep, x[n], col = cc)# *does* draw at 5+ep .. ------ i.e. segments does not follow the general idea of ``not drawing when color is NA '' (note that there is no compatibility issue here, since S-plus does not allow NA colors--and vectorized ones in most cases--anyway.) And this seems to be ``on purpose'' : in src/main/plot.c in do_segments(), around line 1560, we have dd->gp.col = INTEGER(col)[i % ncol]; if (dd->gp.col == NA_INTEGER) dd->gp.col = dd->dp.col; which means in S language that col = NA will be translated to col = par("col") Any reason why this would be a good idea ? Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._