addSmooth: Add a Smooth Line

View source: R/addSmooth.R

addSmoothR Documentation

Add a Smooth Line

Description

Adds a smoothed line to a scatter plot.

Usage

addSmooth(x, y, Smooth = "loess.smooth", ..., Smooth.along = "x",
  Plot = list(name = "", what = "lines", type = "solid", width =
  "standard", color = "black"), current = list(yaxis.log = FALSE,
  yaxis.rev = FALSE, xaxis.log = FALSE))

## Default S3 method:
addSmooth(x, y, Smooth = "loess.smooth", ...,
  Smooth.along = "x", Plot = list(name = "", what = "lines", type =
  "solid", width = "standard", color = "black"), current = list(yaxis.log
  = FALSE, yaxis.rev = FALSE, xaxis.log = FALSE))

## S3 method for class 'list'
addSmooth(x, y, Smooth = "loess.smooth", ...,
  Smooth.along = "x", Plot = list(name = "", what = "lines", type =
  "solid", width = "standard", color = "black"), current = list(yaxis.log
  = FALSE, yaxis.rev = FALSE, xaxis.log = FALSE))

Arguments

x

the x-axis data. For method list, x is a list that contains components x and y and the y argument is not used. Missing values are permitted and ignored in the smooth.

y

the y-axis data. Missing values are permitted and ignored in the smooth.

Smooth

the name of the smoothing function. See Details.

...

additional parameters for the function names in Smooth.

Smooth.along

the data along which the smoother is run. Must be either "x," which smooths y along x resulting in a horzontal line, or "y," which smooths x along y resulting in a vertical line.

Plot

parameters defining the characteristics of the plot. See setPlot for a description of the parameters.

current

the current plot information. Typically, this would be the output from one of the graph creation functions like xyPlot.

Details

The value for Smooth must the name of a smoothing function as a character string. The default is "loess.smooth" but any smoother that accepts arguments names x and y and other arguments controlling the smooth and returns a list with components named x and y can be used. Examples of other smoothers in base R are "supsmu" and "smooth.spline."

Value

The current plot information.

Note

If an error is generated from the smoother, then nothing is added to the graph, an error is printed, the returned object contains missing values for the data that should have been plotted, and the explanation is not updated.

See Also

addXY, xyPlot

Examples

## Not run: 
set.seed(1)
X <- rnorm(32)
Y <- X + rnorm(32)
setGD()
AA.pl <- xyPlot(X, Y)
addSmooth(AA.pl)
# For more details of addSmooth see
vignette(topic="GraphAdditions", package="smwrGraphs")

## End(Not run)

USGS-R/smwrGraphs documentation built on Oct. 11, 2022, 6:11 a.m.