[R] help change auto.key colors in xyplot

Dieter Menne dieter.menne at menne-biomed.de
Fri Feb 13 20:22:57 CET 2009

Dimitri Liakhovitski <ld7631 <at> gmail.com> writes:

> the code below works just fine to produce a dotplot. However, I am not
> successful changing the color of the lines in the legend (auto.key).
> If I add col=..., it only changes the color of the letters in the
> legend, but not the color of the lines.

I prefer to set pch and friends outside the panel function to 
avoid clutter, and to set the parameters globally, thus forcing
my plots to be similar. This is a matter of taste, though.

On Windows, the key looks a bit ugly now.

Group 1 o ----
2       o-----  

I am not very happy that the lwd is not honored by the key.
Lines in lwd 2 (plot) and in lwd 1 (default key) do have a quite
different subjective color hue. Any way around this, Deepayan?

(Besides using ggplot2, as Hadley would argue ??)



sp = trellis.par.get("superpose.line")

dotplot(c(d[[1]],d[[3]])~rep(d[[2]],2),groups=rep(c("Group 1","Group
2"),each=nrow(d)),main=list("Chart Title",cex=1),
    xlab=list("Title for X",cex=.9,font=2),
    ylab=list("Title for Y",cex=.9,font=2),
    auto.key = list(space = "top", points = T, lines = T,cex=.9),
    panel = function(y,x,...)
      panel.grid(h = -1, v = -1, col = "gray", lty ="dotted", ltx="dotted")
      panel.superpose(x,y,... )
      ltext(x, y, labels=round(y,3),cex=.8,col="black",font=2,

More information about the R-help mailing list