[R] Key colour problem with lattice plot

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Oct 23 01:35:18 CEST 2006


On 10/22/06, Geoff Russell <geoffrey.russell at gmail.com> wrote:
> Many thanks Deepayan,
>
> On 10/23/06, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote:
> > On 10/22/06, Geoff Russell <geoffrey.russell at gmail.com> 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:

barchart(rownames(example)~example$LandFill+example$Ruminants,
         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:

Usage:

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

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.

-Deepayan

>
> Cheers,
> Geoff.



More information about the R-help mailing list