Wladimir Eremeev
2003-May-13 14:14 UTC
[R] several regression lines in panel of xyplot (trellis graphics)
Dear r-help, I need to draw xyplot() graphs with several regression lines: one line for the whole range of x (the variable on the horizontal axis) and two additional lines for subranges of x. Is it possible to make first regression line (panel.lmline(x,y,...);) to be drawn on the whole graph and regression lines of the subsets to be drawn only over their subsets? I have defined plot.panel=function(x,y,...){ panel.xyplot(x,y,...); panel.lmline(x,y,...); panel.lmline(x[1:9],y[1:9],...); panel.lmline(x[10:23],y[10:23],...); panel.grid(h=-1,v=-1,...); }; then I draw plots: xyplot(<blah-blah-blah>,panel=plot.panel,<...>) This command draws graphics, but all regression lines on them are drawn from the left side to the right side, i.e. over the whole x range... -- Best regards Wladimir Eremeev mailto:wl at eimb.ru =========================================================================Research Scientist Leninsky Prospect 33, Space Monitoring & Ecoinformation Systems Sector, Moscow, Russia, 119071, Institute of Ecology, Phone: (095) 135-9972; Russian Academy of Sciences Fax: (095) 954-5534
Douglas Bates
2003-May-13 14:39 UTC
[R] several regression lines in panel of xyplot (trellis graphics)
Wladimir Eremeev <wl at eimb.ru> writes:> Dear r-help, > > I need to draw xyplot() graphs with several regression lines: > one line for the whole range of x (the variable on the horizontal > axis) and two additional lines for subranges of x. > > Is it possible to make first regression line (panel.lmline(x,y,...);) > to be drawn on the whole graph > and regression lines of the subsets to be drawn only over their subsets? > > I have defined > plot.panel=function(x,y,...){ > panel.xyplot(x,y,...); > panel.lmline(x,y,...); > panel.lmline(x[1:9],y[1:9],...); > panel.lmline(x[10:23],y[10:23],...); > panel.grid(h=-1,v=-1,...); > }; > > then I draw plots: > xyplot(<blah-blah-blah>,panel=plot.panel,<...>) > > This command draws graphics, but all regression lines on them are > drawn from the left side to the right side, i.e. over the whole x > range...I think you will need to do the linear model fits to the data subsets within the panel function then use panel.segments to add the lines.