panel.smoother {latticeExtra} | R Documentation |
Plot a smoothing line with standard error bounds.
Description
Plot a smoothing line with standard error bounds.
This is based on the stat_smooth
function from ggplot2.
Usage
panel.smoother(x, y, form = y ~ x, method = "loess", ...,
se = TRUE, level = 0.95, n = 100,
col = plot.line$col, col.se = col,
lty = plot.line$lty, lwd = plot.line$lwd,
alpha = plot.line$alpha, alpha.se = 0.25, border = NA,
## ignored: ##
subscripts, group.number, group.value,
type, col.line, col.symbol, fill,
pch, cex, font, fontface, fontfamily)
Arguments
x , y |
data points. If these are missing, they will be looked for in the
environment of |
form , method |
the smoothing model is constructed (approximately) as
|
... |
further arguments passed on to the model function ( |
se , level |
estimate standard errors on the smoother, at the given |
n |
number of equi-spaced points on which to evaluate the smooth function. |
col , col.se , lty , lwd , alpha , alpha.se , border |
graphical parameters. |
subscripts , group.number , group.value , type , col.line , col.symbol , fill , pch , cex , font , fontface , fontfamily |
ignored. |
Details
This should work with any model function that takes a formula
argument, and has a predict
method with a se
argument.
Author(s)
Felix Andrews felix@nfrac.org
Based on stat_smooth
by Hadley Wickham.
See Also
panel.loess
,
panel.quantile
,
stat_smooth
Examples
set.seed(1)
xy <- data.frame(x = runif(100),
y = rt(100, df = 5),
y2 = rt(100, df = 5) + 1)
xyplot(y ~ x, xy, panel = function(...) {
panel.xyplot(...)
panel.smoother(..., span = 0.9)
})
## per-group layers with glayer (pass `...` to get styles)
xyplot(y + y2 ~ x, xy) +
glayer(panel.smoother(...))
## natural spline with 5 degrees of freedom
if (require("splines"))
xyplot(y ~ x, xy) +
layer(panel.smoother(y ~ ns(x,5), method = "lm"))
## thin plate regression spline with smoothness
## chosen by cross validation (see ?mgcv::gam)
if (require("mgcv"))
xyplot(y ~ x, xy) +
layer(panel.smoother(y ~ s(x), method = "gam"))
## simple linear regression with standard errors:
xyplot(y ~ x, xy) +
layer(panel.smoother(x, y, method = "lm"), style = 2)