geom_smoothgeom_smooth(mapping=NULL, data=NULL, stat="smooth", position="identity", ...)
Add a smoothed condition mean.
This page describes geom_smooth, see layer and qplot for how to create a complete plot from individual components.
What do you think of the documentation? Please let me know by filling out this short online survey.
The following aesthetics can be used with geom_smooth. Aesthetics are mapped to variables in the data with the aes function: geom_smooth(aes(x = var)). Note that you do not need quotes around the variable name.
Scales control how the variable is mapped to the aesthetic and are listed after each aesthetic.
| Aesthetic | Default | Related scales |
|---|---|---|
| x | required | continuous, date, datetime, discrete |
| y | required | continuous, date, datetime, discrete |
| colour | #3366FF | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| fill | grey60 | brewer, gradient, gradient2, gradientn, grey, hue, identity, manual |
| size | 0.5 | identity, manual, size |
| linetype | 1 | identity, linetype, manual |
| weight | 1 | |
| alpha | 0.4 |
Layers are divided into groups by the group aesthetic. By default this is set to the interaction of all categorical variables present in the plot.
Parameters control the appearance of the geom. In addition to the parameters listed below (if any), any aesthetic can be used as a parameter, in which case it will override any aesthetic mapping.
This function returns a layer object.
> # 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(ymin = lcl, ymax = ucl), data=grid, stat="identity")
![]()
What do you think of the documentation? Please let me know by filling out this short online survey.