Richard,

Thank you for a clear example, it works. I tried to play with
superpose.polygon before to no avail, this clarifies things.

Another question: would you know how to add gridlines to the plot? I'd like
to have a few horizontal gridlines on my barchart plot for better
readability. Do I have to write a wrapper for panel.barchart?

Thanks
Alex

On Tue, Sep 16, 2008 at 10:49 AM, <[EMAIL PROTECTED]> wrote:

> > I have a basis question regarding the use of color in the lattice
> package. I
> > read the ?barchart help page and searched the R archives but could not
> > understand how to do it.
> >
> > I just need to plot a barchart using specific colors for my groups, e.g.
> > green and red instead of the default lattice colors. How do I do that?
> >
> > If I say:
> >     barchart(x ~ a_factor, groups=my_groups, data=my_data,
> col=c('green',
> > 'red'), auto.key=TRUE)
> >
> > then my barplot has the correct colors, but the legend does not. What is
> the
> > correct approach to set colors in barchart?
>
> Two possibilities:
> 1. Manually specify the colours of the rectangles in the key by using the
> key argument instead of auto.key
>
> my_cols <- c("green", "red", "blue")
> barchart(yield ~ site,
>   groups=variety,
>   data = barley,
>   col=my_cols,
>   key=list(text=list(levels(barley$variety)),
> rectangles=list(col=my_cols)))
>
> 2. Set superpose.polygon$col in the plot settings instead of using the col
> argument, e.g.
>
> barchart(yield ~ site,
>   groups=variety,
>   data = barley,
>   auto.key=TRUE,
>   par.settings=list(superpose.polygon=list(col=my_cols)))
>
> Regards,
> Richie.
>
> Mathematical Sciences Unit
> HSL
>
>
> ------------------------------------------------------------------------
> ATTENTION:
>
> This message contains privileged and confidential information intended
> for the addressee(s) only. If this message was sent to you in error,
> you must not disseminate, copy or take any action in reliance on it and
> we request that you notify the sender immediately by return email.
>
> Opinions expressed in this message and any attachments are not
> necessarily those held by the Health and Safety Laboratory or any person
> connected with the organisation, save those by whom the opinions were
> expressed.
>
> Please note that any messages sent or received by the Health and Safety
> Laboratory email system may be monitored and stored in an information
> retrieval system.
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------
> Scanned by MailMarshal - Marshal's comprehensive email content security
> solution. Download a free evaluation of MailMarshal at www.marshal.com
> ------------------------------------------------------------------------
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to