[Rd] colours in dotchart (PR#4343)

ligges at statistik.uni-dortmund.de ligges at statistik.uni-dortmund.de
Mon Sep 29 15:36:50 MEST 2003


> 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


Thanks 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



More information about the R-devel mailing list