1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/plot.r
3\name{print.ggplot}
4\alias{print.ggplot}
5\alias{plot.ggplot}
6\title{Explicitly draw plot}
7\usage{
8\method{print}{ggplot}(x, newpage = is.null(vp), vp = NULL, ...)
9
10\method{plot}{ggplot}(x, newpage = is.null(vp), vp = NULL, ...)
11}
12\arguments{
13\item{x}{plot to display}
14
15\item{newpage}{draw new (empty) page first?}
16
17\item{vp}{viewport to draw plot in}
18
19\item{...}{other arguments not used by this method}
20}
21\value{
22Invisibly returns the result of \code{\link[=ggplot_build]{ggplot_build()}}, which
23is a list with components that contain the plot itself, the data,
24information about the scales, panels etc.
25}
26\description{
27Generally, you do not need to print or plot a ggplot2 plot explicitly: the
28default top-level print method will do it for you. You will, however, need
29to call \code{print()} explicitly if you want to draw a plot inside a
30function or for loop.
31}
32\examples{
33colours <- list(~class, ~drv, ~fl)
34
35# Doesn't seem to do anything!
36for (colour in colours) {
37  ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
38    geom_point()
39}
40
41# Works when we explicitly print the plots
42for (colour in colours) {
43  print(ggplot(mpg, aes_(~ displ, ~ hwy, colour = colour)) +
44    geom_point())
45}
46}
47\keyword{hplot}
48