[Rd] colours in dotchart (PR#4343)

ligges at statistik.uni-dortmund.de ligges at statistik.uni-dortmund.de
Wed Oct 1 12:33:40 MEST 2003


Martin Maechler wrote:

>>>>>>"UweL" == Uwe Ligges <ligges at statistik.uni-dortmund.de>
>>>>>>    on Mon, 29 Sep 2003 14:36:50 +0200 (MET DST) writes:
> 
> 
>     >> i.wilson at maths.abdn.ac.uk wrote:
>     >> 
>     >> 
>     >>> Problem:  neither fg or bg
>     >>> nor color work properly in dotchart.
>     >>> 
>     >>> version:  R-1.7.1 for windows
>     >>> 
>     >>> code which shows the errors:
>     >>> 
>     >>> x <-
>     >>> 
>     >> 
>     >> matrix(rnorm(16),ncol=2,dimnames=list(paste("a",1:8,sep=""),c("before","afte
>     >> 
>     >>> r")))
>     >>> dotchart(x,fg="blue",bg="lightgrey")
>     >> 
>     >> 
>     >> That's *not* a bug! It is not documented that *all* graphical parameters
>     >> known from par() do work in dotchart() or any other high-level function
>     >> (you won't find many!).
>     >> 
>     >> Instead, use
>     >> 
>     >> par(fg = "blue", bg = "lightgrey")
>     >> dotchart(x)
>     >> 
>     >> 
>     >> 
>     >>> dotchart(x,color=c("red","blue"))
>     >> 
>     >> 
>     >> That's *not* a bug! "color" is recycled, but in another way than you
>     >> expected.
>     >> 
>     >> Instead, use
>     >> 
>     >> dotchart(x, color = rep(c("red", "blue"), each = nrow(x)))
>     >> 
>     >> 
>     >> Please do submit bug reports if you are sure that's a bug. For questions
>     >> use the mailinglist r-help, please.
>     >> 
>     >> 
>     >> Uwe Ligges
> 
> 
>     UweL> Thanks to Ian Wilson who pointed out in a private
>     UweL> message that my first shot was wrong (Sorry!):
> 
> less wrong than you say here, excuse but
> your first answer was better, Uwe, namely
>   >> Instead, use
>   >> 
>   >> par(fg = "blue", bg = "lightgrey")
>   >> dotchart(x)
> 
>     UweL> a) Indeed, it is documented that dotchart() supports
>     UweL> an argument "bg".  Is it really meant as background
>     UweL> colour of the whole plot? 
> 
> No! It's not!  It's meant (and used!) as  `bg' argument to
> points -- see the lightblue inner color of points in
> example(points).  
> The only bug here is the `bg' argument documentation in
> dotchart.Rd  {well, and the basic design "infelicity" of using
> 	      "bg" with two different meanings in R graphics ;-)}
> 
>     UweL> colour of the whole plot? I's propose to either remove
>     UweL> that argument, or implement it to fill the whole
>     UweL> background of the plot (as in the proposal below), or
>     UweL> document it in a way that tells us it's only expected
>     UweL> to fill emtpy plotting characters.
> 
> (proposal rejected, see above)
> 
> 
>     UweL> b) The argument "color" works for the points, but not so for their 
>     UweL> labels. The proposal (by Ian) is to remove the loops. Does that break 
>     UweL> anything? At least, I cannot imagine any point right now.
> 
> I think you (Ian & Uwe) have a good point here.
> This might (or may not) still go as a "trivial bug fix" for 1.8.0.
> {If you want to help, please try to use "diff -u" (or "diff -c")
> for a patch.. }
> But I first need to get my grips on dendrogram buggyness.
> 
> Martin


So here's a proposal for dotchart.R (Anyone who can imagine why the loop 
had been introduced? Are we breaking anything when rempoving the loop?):


@@ -67,9 +67,8 @@
      linch <- max(strwidth(labels, "inch"), na.rm = TRUE)
      loffset <- (linch + 0.1)/lheight
      labs <- labels[o]
-    for(i in 1:n)
-        mtext(labs[i], side = 2, line = loffset, at = y[i], adj = 0,
-          col = color, las = 2, cex = cex, ...)
+    mtext(labs, side = 2, line = loffset, at = y, adj = 0,
+        col = color, las = 2, cex = cex, ...)
      }
      abline(h = y, lty = "dotted", col = lcolor)
      points(x, y, pch = pch, col = color, bg = bg)
@@ -77,9 +76,8 @@
      gpos <- rev(cumsum(rev(tapply(groups, groups, length)) + 2) - 1)
      ginch <- max(strwidth(glabels, "inch"), na.rm = TRUE)
      goffset <- (max(linch+0.2, ginch, na.rm = TRUE) + 0.1)/lheight
-    for(i in 1:nlevels(groups))
-        mtext(glabels[i], side = 2, line = goffset, at = gpos[i],
-          adj = 0, col = gcolor, las = 2, cex = cex, ...)
+    mtext(glabels, side = 2, line = goffset, at = gpos,
+        adj = 0, col = gcolor, las = 2, cex = cex, ...)
      if (!is.null(gdata)) {
          abline(h = gpos, lty = "dotted")
          points(gdata, gpos, pch = gpch, col = gcolor, bg = bg, ...)



an one for dotchart.Rd:


@@ -31,7 +31,9 @@
    \item{pch}{the plotting character or symbol to be used.}
    \item{gpch}{the plotting character or symbol to be used for group
      values.}
-  \item{bg}{the background color to be used.}
+  \item{bg}{the background color of plotting characters or symbols to
+    be used; use \code{\link{par}} to set the background color of the
+    whole plot.}
    \item{color}{the color(s) to be used for points an labels.}
    \item{gcolor}{the single color to be used for group labels and
      values.}


Uwe Ligges



More information about the R-devel mailing list