\HeaderA{ggsmooth}{Grob function: smooth}{ggsmooth}
\keyword{hplot}{ggsmooth}
\begin{Description}\relax
Add a smooth line to a plot
\end{Description}
\begin{Usage}
\begin{verbatim}ggsmooth(plot = .PLOT, aesthetics=list(), ..., data=plot$data)\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{plot}] the plot object to modify
\item[\code{aesthetics}] named list of aesthetic mappings, see details for more information
\item[\code{...}] other options, see details for more information
\item[\code{data}] data source, if not specified the plot default will be used
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This grob adds a smoother to the graphic to aid the eye in
seeing important patterns, especially when there is a lot of overplotting.

You can customise this very freely, firstly by choosing the function used
to fit the smoother (eg. \code{\LinkA{loess}{loess}}, \code{\LinkA{lm}{lm}}, \code{\LinkA{rlm}{rlm}},
\code{\LinkA{gam}{gam}}, \code{\LinkA{glm}{glm}}) and the formula used to related the y and x
values (eg. \code{y \textasciitilde{} x}, \code{y \textasciitilde{} poly(x,3)}).

This smoother is automatically restricted to the range of the data.  If you
want to perform predictions (or fit more complicated variabels with covariates)
then you should fit the model and plot the predicted results.

Aesthetic mappings that this grob function understands:

\Itemize{
\item x: x position (required)
\item y: y position (required)
\item size: size of the point, in mm (see \code{\LinkA{scsize}{scsize})}
\item colour: point colour (see \code{\LinkA{sccolour}{sccolour})}
}

These can be specified in the plot defaults (see \code{\LinkA{ggplot}{ggplot}}) or
in the \code{aesthetics} argument.  If you want to modify the position
of the points or any axis options, you will need to add a position scale to
the plot.  These functions start with \code{ps}, eg.
\code{\LinkA{pscontinuous}{pscontinuous}} or \code{\LinkA{pscategorical}{pscategorical}}

Other options:

\Itemize{
\item method: smoothing method (function) to use
\item formula: formula to use in smoothing function
\item se: display one standard error on either side of fit? (true by default)
\item other arguments are passed to smoothing function
}
\end{Details}
\begin{Author}\relax
Hadley Wickham <h.wickham@gmail.com>
\end{Author}
\begin{Examples}
\begin{ExampleCode}p <- ggpoint(ggplot(mtcars, aesthetics=list(y=wt, x=qsec)))
ggsmooth(p)
ggsmooth(p, span=0.9)
ggsmooth(p, method=lm)
ggsmooth(p, method=lm, formula = y~splines::ns(x,3))
ggsmooth(p, method=MASS::rlm, formula = y~splines::ns(x,3))\end{ExampleCode}
\end{Examples}

