[Rd] segments(*, col = c(..,NA,..)) {was "color NA ..."}

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 10 Jul 2001 19:09:20 +0200

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