> 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 inform...{{dropped:20}}

______________________________________________
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