loess_smooth: Fit loess curves

View source: R/plot.R

loess_smoothR Documentation

Fit loess curves

Description

Add a smooth curve computed by loess to a scatter plot.

Usage

loess_smooth(x, ...)

## S3 method for class 'formula'
loess_smooth(formula, data, ...)

## Default S3 method:
loess_smooth(
  x,
  y = NULL,
  ...,
  conf = 0.95,
  n = 50L,
  sd = TRUE,
  fix_extremes = FALSE
)

## S3 method for class 'loess_smooth'
print(x, ...)

## S3 method for class 'loess_smooth'
plot(
  x,
  y,
  ...,
  col.line = 1L,
  col.ci = col.line,
  alpha.ci = 0.5,
  xlab = NULL,
  ylab = NULL,
  ci = c("none", "lines", "band")
)

Arguments

x, y

the x- and y-axes for the plot

...

additional arguments passed to or from other methods

formula

a formula of the form y ~ x giving the x- and y- axes for the plot

data

a data frame (or list) from which the variables in formula should be taken

conf

the confidence interval to calculate

n

the number of points at which to evaluate the smooth curve

sd

logical; if TRUE, the standard deviation of the square of the residuals are used to calculate the confidence intervals; otherwise, the standard errors from predict.loess are used

fix_extremes

logical; if TRUE, the extremes of the fitted lines will run through {x_1, y_1} and {x_n, y_n}

col.line, col.ci

colors for the smoothed curve and confidence intervals (lines or band)

alpha.ci

alpha transparency for the confidence band

xlab, ylab

the x- and y-axis labels

ci

type of confidence interval to plot, one of "none" for no plotting, "lines" for lines only, or "band" for a semi-transparent color band

See Also

loess.smooth

Examples

plot(mpg ~ wt, mtcars)
lo <- loess_smooth(mpg ~ wt, mtcars)
lines(lo$x, lo$y)
lines(lo$x, lo$upper, lty = 2)
lines(lo$x, lo$lower, lty = 2)

plot(lo)
plot(lo, ci = 'lines')
plot(lo, ci = 'band')


raredd/plotr documentation built on Nov. 19, 2023, 4:09 a.m.