geom_smooth {ggplot2}R Documentation

geom_smooth

Description

Add a smoothed condition mean.

Usage

geom_smooth(mapping=NULL, data=NULL, stat="smooth", position="identity", ...)

Arguments

mapping mapping between variables and aesthetics generated by aes
data dataset used in this layer, if not specified uses plot dataset
stat statistic used by this layer
position position adjustment used by this layer
... ignored

Details

This page describes geom_smooth, see layer and qplot for how to create a complete plot from individual components.

Value

A layer

Aesthetics

The following aesthetics can be used with geom_smooth. Aesthetics are mapped to variables in the data with the aes function: geom\_smooth(\code{aes}(x = var))

Author(s)

Hadley Wickham, http://had.co.nz/

See Also

Examples

## Not run: 
# See stat_smooth for examples of using built in model fitting
# if you need some more flexible, this example shows you how to
# plot the fits from any model of your choosing

library(ggplot2)
qplot(wt, mpg, data=mtcars, colour=factor(cyl))

model <- lm(mpg ~ wt + factor(cyl), data=mtcars)
grid <- with(mtcars, expand.grid(
  wt = seq(min(wt), max(wt), length = 20),
  cyl = levels(factor(cyl))
))

grid$mpg <- stats::predict(model, newdata=grid)

qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + geom_line(data=grid)

# or with standard errors

err <- stats::predict(model, newdata=grid, se = TRUE)
grid$ucl <- err$fit + 1.96 * err$se.fit
grid$lcl <- err$fit - 1.96 * err$se.fit

qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + geom_smooth(aes(min=lcl, max=ucl), data=grid, stat="identity") 
## End(Not run)

[Package ggplot2 version 0.8.2 Index]