Re: [R] Key colour problem with lattice plot

From: Deepayan Sarkar <>
Date: Sun 22 Oct 2006 - 23:35:18 GMT

On 10/22/06, Geoff Russell <> wrote:
> Many thanks Deepayan,
> On 10/23/06, Deepayan Sarkar <> wrote:
> > On 10/22/06, Geoff Russell <> wrote:
> > > Hi,
> > >
> > > I seem to have a key colour problem with a lattice barchart. The colours on my
> > > key rectangle don't match the colours on the barchart.
> >
> > That's because you are using the wrong colors in the key (see the
> > output of show.settings()).
> I assumed that the sequence of colors for the bars would match the
> sequence for the labels.

I'm not sure what you mean by that, but my intention in pointing you towards show.settings() was to make you realize that you should be using "superpose.polygon" rather than "superpose.symbol" in the value of 'key' in your code. Keep everything else unchanged, and you should get what you want.

> In any event, when I look at show.settings()
> I don't see the cyan color at all. So I tried colors 1 thru 9 without
> success.

I do, so look closer (or tell us what device and what version of R you are using, which may be a factor).

> > I would recommend replacing the 'key' argument with something like
> > 'auto.key = TRUE'.
> Yes, this works except that I need to change the labels from
> example$ruminant to just ruminant. So I probably need to use the
> key argument explicitly.

I said "something like". As the documentation of 'auto.key' in ?barchart and ?simpleKey (which the former points to) suggests, the following works:


         auto.key = list(text=c("Landfill","Enteric Fermentation")))

> I have read MASS on trellis, I've read the
> barchart help and I can't find any specification of the color sequence choices
> in either of these.

Well, ?barchart does say that it will accept arguments to the panel function, and it also asks you to read ?panel.barchart, which says:


     panel.barchart(x, y, box.ratio = 1,
                    col = if (is.null(groups)) plot.polygon$col else

which is explicit enough, in my opinion.

> I'm happy to read any other documentation, but most things I found
> on the net stop short just when the most detail is needed! C'est
> la vie.

When you are using a package you are supposed to consult the accompanying documentation, not a book (which, incidentally, was written for the S-PLUS version, where your code will not work in the first place) or the 'net'. The fact that this documentation is long is not your fault, but you don't really get to complain about it.


> Cheers,
> Geoff. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon Oct 23 09:41:43 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 23 Oct 2006 - 02:30:14 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.