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,
  bandArgs = 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.

bandArgs

controls the confidence band. May be TRUE, FALSE, NULL, NA, or a named list. The confidence level is specified via conf.level. Default is list(conf.level = 0.95).

...

currently ignored.

Details

The confidence band is controlled via bandArgs. 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),
  bandArgs = list(
    conf.level = 0.99,
    col = addOpacity("red", 0.4),
    border = "black"
  )
)