On Fri, Aug 8, 2008 at 2:38 PM, Rainer Hurling <[EMAIL PROTECTED]> wrote: > Dear community, > > I am looking for a possibility to draw 'regression lines' instead of > 'smooth' lines in grouped xyplots. The following code should give you a > small example of the data structure. > > > library(lattice) > data(Gcsemv, package = "mlmRev") > > # Creates artificial grouping variable ... > Gcsemv$Groups <- > ifelse(as.numeric(as.character(Gcsemv$school))>65000, > "Group1", "Group2") > > xyplot(written ~ course | gender, data = Gcsemv, > type = c("g", "p", "smooth"), > groups = Groups, > panel = function(x, y, ...) { > panel.xyplot(x, y, ...) > # Here I want to draw the regression lines > # panel.abline(x, y) > }, > auto.key = list(space = 'right'))
Does this do what you want?: xyplot(written ~ course | gender, data = Gcsemv, type = c("g", "p", "r"), groups = Groups) The problem with your approach is that the panel function you define doesn't deal with groups. An easy workaround is to use panel.superpose: xyplot(written ~ course | gender, data = Gcsemv, type = c("g", "p"), groups = Groups, panel = panel.superpose, panel.groups = function(x, y, ...) { panel.xyplot(x, y, ...) panel.lmline(x, y, ...) }, auto.key = list(space = 'right')) -Deepayan ______________________________________________ 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.