Learn R Programming

DescTools (version 0.99.6)

AddLoess: Add a Loess Smoother

Description

Add a loess smoother to an existing plot. The function first calculates the prediction of a loess object for a reasonable amount of points, then adds the line to the plot and inserts a polygon with the confidence intervals.

Usage

## S3 method for class 'default':
AddLoess(x, y, ...) 

## S3 method for class 'formula':
AddLoess(formula, data, col = "#8296C4FF", lwd = 2, lty = "solid", 
                 type = "l", n = 100, conf.level = 0.95, args.band = NULL, ...)

Arguments

x, y
vectors giving the coordinates of the points in the scatter plot.
formula
a formula specifying the numeric response and one to four numeric predictors (best specified via an interaction, but can also be specified additively). Will be coerced to a formula if necessary.
data
an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from whi
col
linecolor of the smoother. Default is a lightblue color #8296C4FF.
lwd
line width of the smoother.
lty
line type of the smoother.
type
type of plot, defaults to "l".
n
number of points used for plotting the fit.
conf.level
confidence level for the confidence interval. Set this to NA, if no confidence band should be plotted. Default is 0.95.
args.band
list of arguments for the confidence band, such as color or border (see DrawBand).
...
further arguments are passed to loess()

Value

  • The computed object of class "loess".

See Also

loess, scatter.smooth

Examples

Run this code
par(mfrow=c(1,2))

x <- runif(100)
y <- rnorm(100)
plot(x, y)
AddLoess(x, y)

# the formula interface is implemented as well:
data(d.pizza)
plot(temperature ~ delivery_min, data=d.pizza)
AddLoess(temperature ~ delivery_min, data=d.pizza)

plot(temperature ~ delivery_min, data=d.pizza)
AddLoess(temperature ~ delivery_min, data=d.pizza, conf.level = 0.99, 
         args.band = list(col=SetAlpha("red", 0.4), border="black") )

# the default values from scatter.smooth
AddLoess(temperature ~ delivery_min, data=d.pizza, 
         span=2/3, degree=1, family="symmetric", col="red")

Run the code above in your browser using DataLab