Scatterplot smoothing
Example 1: A single lowess curve

The lowess(x,y) function can be used directly to add a lowess curve to a plot:

plot(urb,infmor)
lines(lowess(urb,infmor))

Several lowess curves on the same scatterplot

Here we add several lowess curves with different smoothing window spans. f=.1 means that the smoothing window (span) includes a fraction of .1 of the observations (i.e. 10% of the observations).

plot(urb,infmor)
lines(lowess(urb,infmor,f=.2),col="red")
lines(lowess(urb,infmor,f=.4),col="blue")
lines(lowess(urb,infmor,f=.6),col="green")
lines(lowess(urb,infmor,f=.8),col="black")
loess()

loess() is a more recent version that offers many more options; variables can be specified using a formula.

See also