[R] help change auto.key colors in xyplot

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Feb 13 22:38:23 CET 2009


On Fri, Feb 13, 2009 at 11:22 AM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
> 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 ----
> Group
> 2       o-----

[That's because the code got wrapped around, breaking "Group 2".]

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

For the typical situation where you want the same colors for lines and
points, I find the

  par.settings = simpleTheme(col=..., lwd=...)

construct very useful. Also note the slightly different key:

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),
        type="b",

        par.settings = simpleTheme(col=c("blue","red"),
                                   pch=20, cex=1.3, lwd=2),
        auto.key = list(space = "top", points = FALSE,
                        lines = TRUE, type = "b"),

        xlab=list("Title for X",cex=.9,font=2),
        ylab=list("Title for Y",cex=.9,font=2),
        panel = function(y,x,...) {
            panel.grid(h = -1, v = -1,
                       col = "gray", lty ="dotted")
            panel.superpose(x,y,... )
            ltext(x, y, labels=round(y,3),cex=.8,col="black",font=2,
                  adj=c(-0.2,1))
        })

For different colors for lines and points, you do need to be more
verbose, and change the line and symbol settings separately:


trellis.par.set(superpose.line = list(col=c("blue","red"), lwd = 2),
                superpose.symbol = list(cex = 1.3, pch = 20),
                reference.line = list(col = "gray", lty ="dotted"))


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),
        type="b",
        auto.key = list(space = "top", points = TRUE, lines = TRUE),
        xlab=list("Title for X",cex=.9,font=2),
        ylab=list("Title for Y",cex=.9,font=2),
        panel = function(y,x,...) {
            panel.grid(h = -1, v = -1)
            panel.xyplot(x, y, ...)
            ltext(x, y, labels=round(y,3),
                  cex=.8,col="black",font=2,
                  adj=c(-0.2,1))
        })

-Deepayan




More information about the R-help mailing list