Skip to contents

Add a loess smoother to an existing plot. The function first calculates predictions from a loess object and then adds the fitted smoother together with an optional confidence band.

Usage

# S3 method for class 'loess'
lines(
  x,
  col = .useTheme,
  lwd = 2,
  lty = "solid",
  type = "l",
  n = 100,
  band = list(conf.level = 0.95),
  ...
)

Arguments

x

a fitted loess() object.

col

line color of the smoother. .useTheme (default) resolves to getTheme()$twin[1] - the first of the theme's two-color pair (see theme).

lwd

line width.

lty

line type.

type

plotting type passed to lines().

n

number of points used for plotting the fit.

band

controls the confidence band. May be TRUE, FALSE, NULL, NA, or a named list. The confidence level is specified via conf.level, all other elements are graphical parameters of the band. Default is list(conf.level = 0.95).

...

further graphical parameters passed to lines() for the smoother.

Value

No return value (invisible NULL), called for its side effect of adding the smoother and its confidence band to the current plot.

Details

The confidence band is controlled via band. This argument may be:

  • FALSE, NULL or NA: suppress the band

  • TRUE: draw the band with default settings

  • a named list: customize the band appearance and confidence level

Note

Loess can result in substantial computational load for large datasets.

See also

Examples

x <- runif(100)
y <- rnorm(100)

plot(x, y)
lines(loess(y ~ x))


plot(dist ~ speed, cars)
lines(
  loess(dist ~ speed, cars),
  band = list(
    conf.level = 0.99,
    col = addOpacity("red", 0.4),
    border = "black"
  )
)