[R] Place more than one key with xyplot

Deepayan Sarkar deepayan at stat.wisc.edu
Thu Feb 24 17:48:24 CET 2005


On Thursday 24 February 2005 06:12, Gesmann, Markus wrote:
> Dear R-users
>
> I have some trouble to generate more than one key with xyplot using
> the legend argument.
> I would like one key with rectangles:
>
> library(lattice)
> library(grid)
> key1 <- list(rectangles = list(col= c(rev(heat.colors(5))[1:5],
>                                  rev(heat.colors(5))[4:1])),
>                     title="Percentiles",
>                     space="right",
>                     text = list(lab = rev(c(" 5-15", "15-25",
> "25-35", "35-45",
>                                   "45-55","55-65", "65-75", "75-85",
> "85-95"))),
>                     columns = 1)
>
> and another one with lines:
>
> key2 <- list(lines=list(col=2), text=list(lab="Mean"))
>
> Each of them works fine:
>
> xyplot(1~1, key = key1)
> xyplot(1~1, key = key2)
>
> Unfortunately I don't really understand which "fun" (for legend) I
> have to use.
> The following line does not work.
>
> xyplot(1~1, legend = list(right=list(key1, fun="grob"),top=list(key2,
> fun="grob")))

You want

xyplot(1~1, 
       legend = list(right = list(fun="draw.key", 
                         args = list(key = key1, draw = FALSE)),
                     top = list(fun="draw.key", 
                         args = list(key = key2, draw = FALSE))))

?draw.key should explain why. 

Deepayan




More information about the R-help mailing list