\HeaderA{ggerrorbar}{Grob function: error bars}{ggerrorbar}
\keyword{hplot}{ggerrorbar}
\begin{Description}\relax
Add error bars to a plot
\end{Description}
\begin{Usage}
\begin{verbatim}ggerrorbar(plot = .PLOT, aesthetics = list(), ..., data = NULL)\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
The error bar grob adds error bars to a plot.  Thanks to Timm
Danker for supplying some initial code and the motivation to include
it in ggplot.

Aesthetic mappings that this grob function understands:

\Itemize{
\item \code{x}:x position (required)
\item \code{y}:y position (required)
\item \code{plus}:length of error bar in positive direction (required)
\item \code{minus}:length of error bar in negative direction (defaults to -plus)
\item \code{colour}:line colour (see \code{\LinkA{sccolour}{sccolour})}
\item \code{size}:size of the line, in mm (see \code{\LinkA{scsize}{scsize})}
}

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 \code{avoid}: how should overplotting be dealt with?
"none" (default) = do nothing, "stack" = stack bars on top of one another,
"dodge" = dodge bars from side to side
}
\end{Details}
\begin{Author}\relax
Hadley Wickham <h.wickham@gmail.com>
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{ggbar}{ggbar}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}df <- data.frame(x = factor(c(1, 1, 2, 2)), y = c(1, 5, 3, 4), g = c(1, 2, 1, 2), bar = c(0.1, 
0.3, 0.3, 0.2))
df2<-df[c(1,3),];df2

p <- ggbar(ggplot(data=df, aes=list(fill=g, y=y, x=x)))
ggerrorbar(p, aes=list(plus=bar))
qplot(x,y,df,types=list("bar","errorbar"), avoid="dodge",aes=list(fill=g,plus=bar))
qplot(x,y,df,types=list("bar","errorbar"), avoid="dodge",aes=list(fill=g,plus=bar, minus=-2*bar))
qplot(x,y,df2,types=list("point","errorbar"), aes=list(plus=bar), width=0.1)
qplot(x,y,df2,types=list("bar","line","point","errorbar"), aes=list(fill=g,plus=bar,barcolour=g))
qplot(x,y,df2,types=list("jitter","errorbar"), aes=list(plus=bar))
qplot(x,y,df,types=list("point","line","errorbar"), aes=list(plus=bar,id=g), width=0.1)\end{ExampleCode}
\end{Examples}

