Description Usage Arguments Details Author(s) See Also Examples
View source: R/panel.smoother.R
Plot a smoothing line with standard error bounds.
This is based on the stat_smooth
function from ggplot2.
1 2 3 4 5 6 7 8 9 | 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)
|
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. |
This should work with any model function that takes a formula
argument, and has a predict
method with a se
argument.
Felix Andrews felix@nfrac.org
Based on stat_smooth
by Hadley Wickham.
panel.loess
,
panel.quantile
,
stat_smooth
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.