Hi: Here are a couple of ways to superimpose the boxplots with a line, using lattice and latticeExtra. Notice that the boxplots are located at the observed x values - the idea comes straight out of the example on p. 183 of the Lattice book.
library(lattice) library(latticeExtra) # Connect the medians xyplot(nmgml ~ day, data = girafe, panel = panel.bwplot, horizontal = FALSE) + layer(panel.average(..., fun = median, col.line = 'gray30')) # Least squares regression line xyplot(nmgml ~ day, data = girafe, panel = panel.bwplot, horizontal = FALSE) + layer(panel.lmline(...)) Caution: be careful if you have the ggplot2 package loaded, because the layer function in ggplot2 can mask the layer function in latticeExtra. ------------ Aside: I couldn't figure out how to get the horizontal = FALSE argument to work within a single panel function that contains both panel.bwplot and panel.average. I tried xyplot(nmgml ~ day, data = girafe, panel = function(...) { panel.bwplot(..., horizontal = FALSE) panel.average(..., fun = median, col.line = 'gray30') } ) and a couple of variants thereof but couldn't get it to work. If there's an easy solution, I'd be interested in seeing it. HTH, Dennis On Wed, May 12, 2010 at 6:30 AM, Mächler Marc Jaques <ma...@student.ethz.ch>wrote: > Dear R-Experts. > > I collected different datas about Nitrogen content (mg/ml) in Dung. The > dung was eighter fresh (day=0) or had different ages (15,29,47) to observe > nutrient changes over time. > > Now I like to draw a boxplot. > > boxplot(nmgml~day) > abline((nmgml~day) > > The Problem is, that the boxplot considers the day values as groups and not > as time series (neighter when the days are numeric or factors). > > The result is, that the regression line looks different as when I draw a > plot > plot(nmgml~day) > abline(nmgml~day) > > How can I reach that the boxplot's position on the x-axis is relative to > the time value? (and the days are not just treated as groups) > > Data sample (Girafe-Dung) > day nmgml > 1 29 2.72655 > 2 29 2.48820 > 3 15 2.85945 > 4 15 2.58915 > 5 15 2.88345 > 6 15 2.66675 > 7 47 3.29125 > 8 15 2.44085 > 9 29 2.43065 > 10 29 2.43425 > 11 29 2.42705 > 12 0 1.12350 > 13 15 5.10310 > 14 15 0.99880 > 15 0 2.22350 > 16 47 2.18290 > 17 47 2.21570 > 18 47 2.46450 > 19 29 2.53350 > 20 47 2.78550 > 21 47 3.06920 > 22 0 2.65660 > 23 0 2.16650 > 24 0 2.20620 > 25 0 1.91870 > 26 0 2.45160 > 27 0 2.35980 > 28 0 1.99900 > 29 0 2.16300 > 30 15 2.00460 > 31 15 2.56220 > 32 47 2.38650 > 33 29 2.65820 > 34 29 2.47670 > 35 47 2.23770 > 36 29 2.40080 > 37 47 2.12650 > 38 29 2.35950 > > I really apreciate your help > > Sincerly... > > MJMaechler (Zurich, Switzerland) > ______________________________________________ > 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. > [[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.