I have this data file as an example:
>mydata <- rbind(data.frame(Col1 = rnorm(2*1000),Col2 =rep(c("A", "C"), each=1000),Col3=factor(rep(c("YY","NN"), 1000))),data.frame(Col1 = rnorm(1000),Col2 =rep(c("B")),Col3=factor(rep(c("YY","YN"), 500))))
It looks like this:
>head(mydata)
Col1 Col2 Col3
1 -0.1213684 A YY
2 0.1846364 A NN
3 0.4028003 A YY
4 1.4065677 A NN
5 -0.8669333 A YY
6 0.3295806 A NN
Being a Col3 factor type with three levels: NN YY YN
I want to make boxplot using the bwplot lattice and assign a specific color to each level:
red=rgb(249/255, 21/255, 47/255)
amber=rgb(255/255, 126/255, 0/255)
green=rgb(39/255, 232/255, 51/255)
Using the bwplot function:
pl<-bwplot(mydata$Col1~mydata$Col3 | mydata$Col2,data=mydata,
ylab=expression(italic(R)),panel=function(...)
{panel.bwplot(...,groups=mydata$Col3, fill=c(red,amber,green))})
This leads to the following fig.

It is clear that the colors are not related to the levels in my data frame, since the YY field is not always green. Is there a way to assign YY: green, NN: red and YN: yellow?