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

Juan Perez beire55 at yahoo.es
Sat Aug 13 15:31:50 CEST 2016


Thanks Bert
I am not sure what you meant by reading though.
I managed to sort this out, although ideally would exist a better solution. I have created a column in my dataset, and given two codes depending whether older or younger than 40. Afterwards I have applied
xyplot(MOE~Age|Species, groups=Old,
       panel= function(x,y,...){  ## custom panel function to add an overall loess line
         panel.superpose(x,y,...)
         panel.loess(x,y,col="black",lwd=2,...)
       },
       panel.groups = function(x,y,...){
         panel.xyplot(x,y,...)
         panel.loess(x,y,...)
       }) 

This gives a loess line for data younger than 40, another for the ones older, and a third one for all the data. I hope this helps to someone else. Unfortunately, the dataset needs to be modified everytime we want to make a new or different subset.
Best regards
 

    El Viernes 12 de agosto de 2016 21:10, Bert Gunter <bgunter.4567 at gmail.com> escribió:
 

 Try reading ?panel.loess. There is no "subset" argument, so it is of
course ignored.

-- Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Aug 12, 2016 at 9:10 AM, Juan Perez via R-help
<r-help at r-project.org> wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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]]



More information about the R-help mailing list