[R] Regression line limited by the rage of values

Karl Ove Hufthammer karloh at mi.uib.no
Thu May 25 10:57:17 CEST 2006


Andreas Svensson wrote:

> So, how can I constrain the abline to the relevant region, i.e stop
> abline from extrapolating beyond the actual range of data.
> Or should I use a function line 'lines' to do this?

One elegant way of doing this is using 'xyplot' from 'lattice' and adding a
loess line with a large value of 'span' (which basically makes is equal to
the ordinary least-squares regression line). Here's a simple example:

library(lattice)
data(iris)
xyplot(Petal.Length~Petal.Width,
       groups=Species, type=c("p","smooth"), span=100, data=iris)

-- 
Karl Ove Hufthammer



More information about the R-help mailing list