\HeaderA{ggplot.default}{Creat a new plot}{ggplot.default}
\aliasA{ggplot}{ggplot.default}{ggplot}
\aliasA{package-ggplot}{ggplot.default}{package.Rdash.ggplot}
\keyword{hplot}{ggplot.default}
\begin{Description}\relax
Create a new ggplot plot
\end{Description}
\begin{Usage}
\begin{verbatim}ggplot.default(data, formula = . ~ ., margins=FALSE, aesthetics=list(), ...)\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{data}] default data frame
\item[\code{formula}] formula describing row and column layout, see \code{\LinkA{reshape}{reshape}} for more details
\item[\code{margins}] a vector of names giving which margins to display, can include grand\_row and grand\_col or uss TRUE to display all margins
\item[\code{aesthetics}] default list of aesthetic mappings (these can be colour, size, shape, line type -- see individual grob functions for more details)
\item[\code{...}] 
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function creates the basic ggplot object which you can then
furnish with graphical objets.  Here you will set
up the default data frame, default aesthetics and the formula that
will determine how the panels are broken apart.  See \code{\LinkA{reshape}{reshape}}
for more details on specifying the facetting formula and margin arguments.

To get started, read the introductory vignette: \code{vignette("introduction", "ggplot")}

Steps to create a plot:

\Enumerate{
\item Create a new plot.  (\code{p <- ggplot(mtcars, aesthetics=list(y=hp, x=mpg))})
\item Set scales (if necessary)
\item Add grobs to the plot (\code{ggpoint(p)})

}

Simple grobs:

\Itemize{
\item \code{\LinkA{ggabline}{ggabline}}: line with given slope and intercept
\item \code{\LinkA{ggarea}{ggarea}}: area (polygons with base on y=0)
\item \code{\LinkA{ggjitter}{ggjitter}}: jittered points (useful for discrete data)
\item \code{\LinkA{ggline}{ggline}}: lines (paths sorted by x-axis values)
\item \code{\LinkA{ggpath}{ggpath}}: paths
\item \code{\LinkA{ggpoint}{ggpoint}}: points
\item \code{\LinkA{ggpolygon}{ggpolygon}}: polygon (paths with the ends joined)
\item \code{\LinkA{ggrect}{ggrect}}: rectangles
\item \code{\LinkA{ggtext}{ggtext}}: text
\item \code{\LinkA{ggtile}{ggtile}}: tiles, like a levelplot
}

Complex grobs:

\Itemize{
\item \code{\LinkA{ggboxplot}{ggboxplot}}: box plot
\item \code{\LinkA{ggcontour}{ggcontour}}: contour lines
\item \code{\LinkA{gg2density}{gg2density}}: 2d density countours
\item \code{\LinkA{gghexagon}{gghexagon}}: hexagon binned plot
\item \code{\LinkA{gghistogram}{gghistogram}}: histogram
\item \code{\LinkA{ggquantile}{ggquantile}}: quantile lines from a quantile regression
\item \code{\LinkA{ggsmooth}{ggsmooth}}: smooths from any model family
}

Look at the documentation of these objects to see many examples of ggplot
in action.

You will also want to add scales to the basic plot to give finer control
over how the data values are mapped to aethetics attributes of the grobs.
For scales that control position of the points see:

\Itemize{
\item \code{\LinkA{pscontinuous}{pscontinuous}}: continuous scales (with optional transformation)
\item \code{\LinkA{pscategorical}{pscategorical}}: categorical scales
}

For other scales, see:

\Itemize{
\item \code{\LinkA{sccolour}{sccolour}}: colour categorical variables using Brewer colour scales
\item \code{\LinkA{scgradient}{scgradient}}: colour continuous scales with a gradient
\item \code{\LinkA{schcl}{schcl}}: map continuous variable to hue, chroma or luminance components
\item \code{\LinkA{schsv}{schsv}}: map continuous variable to hue, saturation or value components
\item \code{\LinkA{sclinetype}{sclinetype}}: line type (solid, dashed, dotted, etc.)
\item \code{\LinkA{scrgb}{scrgb}}: map continuous variable to red, green or blue components
\item \code{\LinkA{scshape}{scshape}}: point shape (glyph)
\item \code{\LinkA{scsize}{scsize}}: point or line size
}

ggplot is different from base and lattice graphics in how you build up the plot.
With ggplot you build up the plot object (rather than the plot on the screen as
in base graphics, or all at once as in lattice graphics.)

Each of the grob and scale functions adds the grob to the plot and returns
the modified plot object.  This lets you quickly experiment with different
versions of the plot, using different grobs or scales.  You can see how this
works in the examples

You can also use \code{summary} to give a quick description of a plot.
\end{Details}
\begin{Author}\relax
Hadley Wickham <h.wickham@gmail.com>
\end{Author}
\begin{SeeAlso}\relax
\url{http://had.co.nz/ggplot}, \code{\LinkA{stamp}{stamp}}, \code{\LinkA{reshape}{reshape}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}p <- ggplot(tips)
summary(p)
ggpoint(p, aesthetic=list(y = tip, x=total_bill))
p <- ggplot(tips, aesthetic=list(y = tip, x=total_bill))
p$title <- "Tips"
summary(p)
ggpoint(p)
ggpoint(p, list(colour=sex))
ggpoint(ggplot(tips, . ~ sex,aesthetics = list(y = tip, x = total_bill)))
p <- ggplot(tips, smoker ~ sex,aesthetics = list(y = tip, x = total_bill))
ggpoint(p)
ggsmooth(ggpoint(p))
ggsmooth(ggpoint(p), method=lm, formula=y~x)
ggsmooth(ggpoint(p), method=MASS::rlm, formula=y~x)
ggabline(ggpoint(p), slope=c(0.1,0.15,0.2))
(p2 <- ggabline(ggpoint(p, aes=list(colour=tip/total_bill)), slope=c(0.1,0.15,0.2)))
summary(p2)
scgradient(p2)
scgradient(p2, midpoint=0.15, high="green", mid="yellow")

p<-ggplot(tips, sex ~ smoker, aesthetics=list(x=tip/total_bill))
gghistogram(p,scale="density")
gghistogram(p,scale="density", breaks=seq(0,1, length=20))

p<-ggplot(tips, . ~ smoker, aesthetics=list(x=sex, y=tip))
ggboxplot(p)
ggboxplot(ggjitter(p))\end{ExampleCode}
\end{Examples}

