[R] Adding loess lines subsetting to each panel in lattice plot

Juan Perez beire55 at yahoo.es
Fri Aug 12 18:10:31 CEST 2016

Hello, I've created an xyplot and I want to add a loess line for x (Age)  <=40 and another for values >40. In a way it is similar to this https://stat.ethz.ch/pipermail/r-help/2009-May/390502.html but still not succcessful.
This is my try:

xyplot(MOE~Age|Species, groups=Site, 
       panel = function(x, y, groups=groups,...) {
        panel.xyplot(x, y, groups=groups,...)
        panel.loess(x,y,subset = x <= 40, col="black")         panel.loess(x,y,subset = x >40, col="red")  
When I run the code it "works" but it plots the loess line for all the data, without subsetting.Any suggestion?
Thank you

	[[alternative HTML version deleted]]

More information about the R-help mailing list