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",
        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



This email message and any attachment(s) is intended solely for the addressee(s)
named above. The information it contains is confidential and may be legally
privileged.  Unauthorised use of the message, or the information it contains,
may be unlawful. If you have received this message by mistake please call the
sender immediately on 64 4 8940100 or notify us by return email and erase the
original message and attachments. Thank you.

The Ministry for Primary Industries accepts no responsibility for changes
made to this email or to any attachments after transmission from the office.

        [[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