[R] Lattice different colours for bars

Duncan Mackay mackay at northnet.com.au
Thu Jun 13 16:04:34 CEST 2013


Hi

The example contained errors in the line with cast and it is too late to check

without a reproducible example i am only guessing

perhaps add a groups argument and supply a col argument to superpose polygon eg

groups = Ikeda,
par.settings = list(superpose.polygon = list(col = 12 colours to suit)),

colur order to match levels of Ikeda

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au



At 16:47 13/06/2013, you wrote:

>On Jun 12, 2013, at 6:43 PM, Andrew McFadden (Andy) wrote:
>
> > Hi all
> >
> > Perhaps this is torturous methodology. I was trying to use 
> lattice to produce a barchart showing the number positive and 
> negative over time. I wasn't quite sure how create a different 
> colour for values of arbo$Ikeda in the example below ie red for 
> ikeda and green for neg.
> >
> >
> > library(reshape)
> > library(lattice)
> >
> > Time=c(rep(6,17), rep(5,17), rep(4,17),
> >       rep(3,17),rep(2,17), rep(1,17))
> > Ikeda=c(rep("Ikeda",6),rep("Neg",11),
> >        rep("Ikeda",0),rep("Neg",17),
> >        rep("Ikeda",1),rep("Neg",16),
> >        rep("Ikeda",0),rep("Neg",17),
> >        rep("Ikeda",0),rep("Neg",17),
> >        rep("Ikeda",0),rep("Neg",17))
> > Theileria=c(rep("Other",6),rep("Neg",11),
> >         rep("Other",12),rep("Neg",5),
> >         rep("Other",12),rep("Neg",5),
> >         rep("Other",14),rep("Neg",3),
> >         rep("Other",14),rep("Neg",3),
> >         rep("Other",13),rep("Neg",4))
> > value=c(rep(1,102))
> > arbo=data.frame(Time, Ikeda,Theileria,value)
> >
> > arbo$Time=as.factor(arbo$Time)
> > levels(arbo$Time)
> >
> > arbo$Time=factor(arbo$Time,
> >                    levels=c(1,2,3,4,5,6),
> >                    labels=c("Dec 2008", "Dec 2009", "Dec 2010",
> >                             "Dec 2011", "Jun 2012", "Dec 2012")
> > )
> >
> > mdat=melt(arbo,measure.var=c(4),id.var=c(1:3),na.rm=FALSE)
> > mdat=cast(mdat,Time +Ikeda~variable,fun.aggregate = c(sum))
>
>barchart(value~Ikeda|Time, data = mdat,
>        type="count",
>              col=c("green","red")[1+(mdat$Ikeda=="Ikeda")],
>        cex=1.1,
>        xlab="PCR positive over time",
>        aspect = c(1.5),layout = c(6, 1),
>        stack=FALSE,
>        strip=strip.custom(strip.names=FALSE, strip.levels=TRUE, 
> bg="light blue"),
>        par.strip.text=list(cex=1.1), scales=list(cex=c(1.1)))
>Any suggestions on how to do this would be appreciated.
>
> >
> > Regards
> >
> > Andrew
> >
> > Investigation and Diagnostic Centre- Upper Hutt
> >
>--
>David Winsemius
>Alameda, CA, USA
>
>______________________________________________
>R-help at 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.



More information about the R-help mailing list