[R] xyplot: legend title + legend on 1 line

Deepayan Sarkar deepayan.sarkar at gmail.com
Fri Dec 15 22:01:56 CET 2006


On 12/15/06, RMan54 <RMan54 at cox.net> wrote:
>
> Does anybody know how in xyplot to put the legend title on one line with the
> legend? I can get the legend on one line with columns=... but the title is
> always on top. I tried a custom key with key=... and text=... but I can't
> put the title text in front of the plotting symbol.
>
> I am looking for the following layout of the legend, on one line:
>
> "Legend Title:" + plot symbol1 + legend text1 + plot symbol2 + legend text2
> + ...

You can create a grob (grid object) representing this legend, or a
function that produces such a grob, and pass it to xyplot through the
'legend' argument (see ?xyplot). The 'key' argument essentially
controls one such built-in function, namely 'draw.key', which does not
support such legends.

Note however, that column types can be repeated in key, so you might
be able to fake such a legend. E.g.:


xyplot(1 ~ 1,
       key =
       list(text = list("title: ", font = 2),
            points = list(pch = 1),
            text = list("1"),
            points = list(pch = 2),
            text = list("2")))

-Deepayan



More information about the R-help mailing list