\HeaderA{ggbar}{Grob function: bars}{ggbar}
\keyword{hplot}{ggbar}
\begin{Description}\relax
Add bars to a plot
\end{Description}
\begin{Usage}
\begin{verbatim}ggbar(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 bar grob produces bars from the y-position to the y=0.

Aesthetic mappings that this grob function understands:

\Itemize{
\item \code{x}:x position (required)
\item \code{y}:y position (required)
\item \code{fill}:fill 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 \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
\item \code{sort}: Should the values of the bars be sorted
}
\end{Details}
\begin{Author}\relax
Hadley Wickham <h.wickham@gmail.com>
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{ggrect}{ggrect}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}cyltab <- as.data.frame(table(cyl=mtcars$cyl))
p <- ggplot(cyltab, aes=list(y=Freq, x=cyl))
ggbar(p)
ggbar(p, fill="white", colour="red")
#Can also make a stacked bar chart
p <- ggplot(mtcars, aes=list(y=1, x=factor(cyl)))
ggbar(p, avoid="stack")
ggbar(p, avoid="stack", colour="red") # Made up of multiple small bars
p <- ggplot(mtcars, aes=list(y=mpg, x=factor(cyl)))
ggbar(p, avoid="stack")
ggbar(p, avoid="dodge", sort=TRUE)
ggbar(p, aes=list(fill=mpg), avoid="dodge", sort=TRUE)
ggbar(p, avoid="stack", sort=TRUE)\end{ExampleCode}
\end{Examples}

