Huapeng, It sounds like you have different y scales on the two plots you want to overlay? If so you could try doubleYScale() from the latticeExtra package.
Please post a minimal, reproducible example (with data-generating code that can be pasted in to R) if you want more help. Regards -Felix On 20 April 2010 07:34, Chen, Huapeng FOR:EX <huapeng.c...@gov.bc.ca> wrote: > Hello R Folks, > > I am new to R. I have been struggling to overlay a barchart with a > xyplot together on one plot but did not get this worked out. Any help > and idea are greatly appreciated. > > I attached R scripts for barchart and xyplot below and also data I used. > What I am trying to do is just to put the barchart and xyplot together > on one plot. > > Huapeng > > > <<dispersal_infestation.csv>> > > ###################################### > ## barchart > dispersal_infestation <- > read.table('Z:/project/bcmpb/pattern_process/data/BCMPB_MODEL/R_stat/dis > persal_infestation.csv', header=T, sep=",") > attach(dispersal_infestation) > dispersal_infestation$Year <- factor(dispersal_infestation$Year, levels > = > c("1999","2000","2001","2002","2003","2004","2005","2006","2007","2008") > , ordered = TRUE) > > barchart(dispersal_infestation$SPG_PER*100 + > dispersal_infestation$SPP_PER*100 + dispersal_infestation$SPP_PER*100 ~ > dispersal_infestation$Year | dispersal_infestation$District, > #data=dispersal_infestation, > layout=c(4,7), > stack=TRUE, > ###################################### > > ###################################### > ## xyplot > > attach(dispersal_infestation) > > dispersal_infestation$Year <- factor(dispersal_infestation$Year, levels > = > c("1999","2000","2001","2002","2003","2004","2005","2006","2007","2008") > , ordered = TRUE) > > library(lattice) > my.theme <- list( > axis.components = list(left = list(tck = 0.5, pad1 = 1, pad2 = > 2), > top = list(tck = 0, pad1 = -1.3, pad2 = > 0), > right = list(tck = 0.5, pad1 = 1, pad2 = > 2), > bottom = list(tck = +0.5, pad1 = 1, pad2 > = 2))) > > trellis.par.set(theme = my.theme) > > panel1 = function(x, y) { > #panel.loess(x, y, lwd=2.5, col="black") > panel.xyplot(x, y, pch=18, col="black", cex=1.5,type='b',lwd=2) > } > > #xyplot(log(dispersal_infestation$COUNT) ~ dispersal_infestation$Year | > dispersal_infestation$ORG_UNIT_N, > xyplot(sqrt(dispersal_infestation$Infestation_NUM) ~ > dispersal_infestation$Year | dispersal_infestation$District, > data=dispersal_infestation, > layout=c(5,5), > strip = strip.custom( bg="light grey"), > panel=panel1, > xlab="Year", > > ylab="Square roots of number of infested cells", > main="BC MPB infestation by forest districts") > ####################################### > > > > > > > > > > ============================= > Huapeng Chen > Landscape Modeling Biologist > Research Branch > Ministry of Forests and Range > Phone: 250-387-2710 > Fax: 250-387-0046 > Email: huapeng.c...@gov.bc.ca > 5th Floor -727 Fisgard Street > Victoria, BC V8W 1N1 > P.O.Box 9519 Stn. Prov. Govt. > Victoria, BC V8W 9C2 > ============================= > > > > ______________________________________________ > 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. > > -- Felix Andrews / 安福立 Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andr...@anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/ ______________________________________________ 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.