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") dotchart(x,color=c("red","blue")) Dr Ian J Wilson Lecturer in Statistics Department of Mathematical Sciences University of Aberdeen King's College Aberdeen, AB24 3UE Tel: +44(0)1224 272609 Fax: +44(0)1224 272607 I.Wilson@maths.aberdeen.ac.uk http://www.maths.abdn.ac.uk/~ijw
i.wilson@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> > Dr Ian J Wilson > Lecturer in Statistics > Department of Mathematical Sciences > University of Aberdeen > King's College > Aberdeen, AB24 3UE > > Tel: +44(0)1224 272609 > Fax: +44(0)1224 272607 > > I.Wilson@maths.aberdeen.ac.uk > http://www.maths.abdn.ac.uk/~ijw
> i.wilson@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 LiggesThanks to Ian Wilson who pointed out in a private message that my first shot was wrong (Sorry!): a) Indeed, it is documented that dotchart() supports an argument "bg". Is it really meant as background colour of the whole plot? I's propose to either remove that argument, or implement it to fill the whole background of the plot (as in the proposal below), or document it in a way that tells us it's only expected to fill emtpy plotting characters. b) The argument "color" works for the points, but not so for their labels. The proposal (by Ian) is to remove the loops. Does that break anything? At least, I cannot imagine any point right now. A fix for both problems could be as follows (against R-1.8.0 beta): 8c8 < opar <- par("mar", "cex", "yaxs") --- > opar <- par("mar", "cex", "yaxs", "bg") 10c10 < par(cex = cex, yaxs = "i") --- > par(cex = cex, yaxs = "i", bg = bg) 70,72c70,71 < 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, ...) 75c74 < points(x, y, pch = pch, col = color, bg = bg) --- > points(x, y, pch = pch, col = color) 80,82c79,80 < 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, ...) 85c83 < points(gdata, gpos, pch = gpch, col = gcolor, bg = bg, ...) --- > points(gdata, gpos, pch = gpch, col = gcolor, ...) Uwe Ligges
>>>>> "UweL" == Uwe Ligges <ligges@statistik.uni-dortmund.de> >>>>> on Mon, 29 Sep 2003 14:36:50 +0200 (MET DST) writes:>> i.wilson@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
Martin Maechler wrote:>>>>>>"UweL" == Uwe Ligges <ligges@statistik.uni-dortmund.de> >>>>>> on Mon, 29 Sep 2003 14:36:50 +0200 (MET DST) writes: > > > >> i.wilson@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. > > MartinSo 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
>>>>> "UweL" == Uwe Ligges <ligges@statistik.uni-dortmund.de> >>>>> on Wed, 1 Oct 2003 11:33:40 +0200 (MET DST) writes:... 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 UweL> So here's a proposal for dotchart.R I have committed it just now as "simple bug fix" to "R 1.8.0beta". UweL> (Anyone who can imagine why the loop had been UweL> introduced? Are we breaking anything when rempoving UweL> the loop?): dotchart() is a very old R function and has a peculiar history. It was there in the very first R version I think I have ever seen (Jul 1995, pre alpha, no version number) -- however with text() {and no for()} there. Later it was renamed to dotplot() {I don't know why} and in Apr 2001 was renamed *back* to dotchart() in order not to resolve a naming conflict with the lattice dotplot() function. Here is the revision text {for dotplot.R back then} where Ross changed from " text(....) " to " for(.....) mtext(....) ">> Revision 1.3 , Tue May 5 08:39:30 1998 UTC (5 years, 4 months ago) by ihaka >> Branch: MAIN >> Changes since 1.2: +88 -79 lines > >> Fixes to dotplot code. Updates to mtext and text.Now, the graphical argument recycling has been in R from early on (as a clear improvement over S-plus!), too, but not as consistently as it became around version 1.2 or so, and particularly not with mtext(). Hence I assume , the change from text() to mtext() needed to introduce the for() loop back then. (so far the archeological/historical account from digging in old stuff ..) Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <><