2
## based on the stat_smooth() function in ggplot2 package.
5
function(x, y, form = y ~ x, method = "loess", ...,
6
se = TRUE, level = 0.95, n = 100,
7
col = plot.line$col, col.se = col,
8
lty = plot.line$lty, lwd = plot.line$lwd,
9
alpha = plot.line$alpha,
10
alpha.se = 0.25, border = NA,
11
## ignored (do not pass to method()):
12
subscripts, group.number, group.value,
13
type, col.line, col.symbol, fill,
14
pch, cex, font, fontface, fontfamily)
16
plot.line <- trellis.par.get("plot.line")
17
if (all(is.na(col)) && !missing(col.line))
19
## allow 'form' to be passed as the first argument
20
missing.x <- missing(x)
21
if (!missing.x && inherits(x, "formula")) {
25
## use 'x' and 'y' if given
26
## otherwise try to find them in the formula environment
28
x <- environment(form)$x
30
y <- environment(form)$y
31
data <- list(x = x, y = y)
32
mod <- do.call(method,
33
c(alist(form, data = data), list(...)))
34
## use the limits of the data, or panel limits, whichever is smaller
35
lims <- current.panel.limits()
36
xrange <- c(max(min(lims$x), min(x)), min(max(lims$x), max(x)))
37
xseq <- seq(xrange[1], xrange[2], length = n)
38
pred <- predict(mod, data.frame(x = xseq), se = se)
40
std <- qnorm(level/2 + 0.5)
41
panel.polygon(x = c(xseq, rev(xseq)),
42
y = c(pred$fit - std * pred$se,
43
rev(pred$fit + std * pred$se)),
44
col = col.se, alpha = alpha.se, border = border)
47
panel.lines(xseq, pred, col = col, alpha = alpha,