Hi, I'd like to plot 4 groups of data using xyplot and panel.superpose so that the points are overlayed on a single plot. For each group of data I'd also like a loess smoothed function (using panel.loess). I have tried the following: xyplot(series ~ time | gr, data=etable, panel = function(x,y, ...) { panel.superpose(x,y, ...) panel.loess(x,y,span=.15) } ) However, this gives me only a single loess curve (collapsed across groups) whereas I would like one curve for each group (just as I get one color for each set of points from the panel.superpose). Is there a way to accomplish this? thanks, Brad Buchsbaum -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 28 Nov 2001, Brad Buchsbaum wrote:> Hi, > > I'd like to plot 4 groups of data using xyplot and panel.superpose so > that the points are overlayed on a single plot. For each group of data > I'd also like a loess smoothed function (using panel.loess). I have > tried the following: > > xyplot(series ~ time | gr, data=etable, > panel = function(x,y, ...) { > panel.superpose(x,y, ...) > panel.loess(x,y,span=.15) > > } > ) > > However, this gives me only a single loess curve (collapsed across > groups) whereas I would like one curve for each group (just as I get one > color for each set of points from the panel.superpose). > > Is there a way to accomplish this?Make a copy of panel.superpose, say panel.multiloess, and replace the call inside it to panel.xyplot by a call to panel.loess. Or start with panel.loess and add subscripts and groups arguments a la panel.superpose. Generally, when using Trellis (and Lattice) you need to customize panel (and prepanel) functions. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Brad, Here is a function adapted from panel.superpose (S+ version). Please note the use of llines instead of lines (bottom of the code). Hope this helps; Renaud panel.superpose.loess <- function(x, y, subscripts, groups, lwd = superpose.line$lwd, lty = superpose.line$lty, col = NULL, f=2/3, iter=3, delta = 0.1*diff(range(x)), ...){ superpose.line <- trellis.par.get("superpose.line") groups <- as.numeric(as.factor(groups))[subscripts] max.groups <- max(groups) lty <- rep(lty, length = max.groups) lwd <- rep(lwd, length = max.groups) if(is.null(col)) { sl <- rep(superpose.line$col, length = max.groups) col <- numeric(max.groups) for(i in 1:max.groups) col[i] <- sl[i]} else col <- rep(col, length = max.groups) N <- seq(along = groups) for(i in sort(unique(groups))) { which <- N[groups == i] j <- which # no sorting llines(lowess(x[j], y[j], f = f, iter = iter, delta = delta), col = col[i], lwd = lwd[i], lty = lty[i], ...) } } library(lattice) data(ethanol) EE <- cut(ethanol$E, breaks = quantile(ethanol$E, prob = seq(0, 1, 1/3)), include.lowest = T) trellis.device(bg = 0) xyplot(NOx ~ C, groups = EE, data = ethanol, key = list(space = "right", title = "EE", text = list(levels(EE), cex = 1.2), lines = list(lty = c(1,2,4), pch = c(1, 8, 16), col = 1:3, type = "b", cex = 1.1)), panel = function(x, y, ...) { panel.superpose(x, y, pch = c(1, 8, 16), col = 1:3, ...) panel.superpose.loess(x, y, lty = c(1,2,4), col = 1:3, ...) } ) Brad Buchsbaum wrote:> > Hi, > > I'd like to plot 4 groups of data using xyplot and panel.superpose so > that the points are overlayed on a single plot. For each group of data > I'd also like a loess smoothed function (using panel.loess). I have > tried the following: > > xyplot(series ~ time | gr, data=etable, > panel = function(x,y, ...) { > panel.superpose(x,y, ...) > panel.loess(x,y,span=.15) > > } > ) > > However, this gives me only a single loess curve (collapsed across > groups) whereas I would like one curve for each group (just as I get one > color for each set of points from the panel.superpose). > > Is there a way to accomplish this? > > thanks, > > Brad Buchsbaum > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Dr Renaud Lancelot, v?t?rinaire CIRAD, D?partement Elevage et M?decine V?t?rinaire (CIRAD-Emvt) Programme Productions Animales http://www.cirad.fr/presentation/programmes/prod-ani.shtml ISRA-LNERV tel (221) 832 49 02 BP 2057 Dakar-Hann fax (221) 821 18 79 (CIRAD) Senegal e-mail renaud.lancelot at cirad.fr -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
For this particular problem, you can use : xyplot(series ~ time, data=etable, groups = gr, panel = "panel.superpose", type = c("p", "smooth"), span=.15) A similar example can be found in example(xyplot) (the second example). Note, however, that this is NOT S-compatible. `type' is an argument accepted by panel.xyplot and panel.superpose, and can be passed as extra arguments to xyplot, as can be `span'. Hope that helps. --- Brad Buchsbaum <bbuchsba at uci.edu> wrote:> Hi, > > I'd like to plot 4 groups of data using xyplot and > panel.superpose so > that the points are overlayed on a single plot. For > each group of data > I'd also like a loess smoothed function (using > panel.loess). I have > tried the following: > > xyplot(series ~ time | gr, data=etable, > panel = function(x,y, ...) { > panel.superpose(x,y, ...) > panel.loess(x,y,span=.15) > > } > ) > > However, this gives me only a single loess curve > (collapsed across > groups) whereas I would like one curve for each > group (just as I get one > color for each set of points from the > panel.superpose). > > Is there a way to accomplish this? > > > thanks, > > Brad Buchsbaum > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-> r-help mailing list -- Read > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: > r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.___________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._