[R] multiple pages with ggplot2 facet_wrap?

hadley wickham h.wickham at gmail.com
Fri Oct 30 14:48:16 CET 2009


On Wed, Oct 28, 2009 at 8:19 PM, Bill Gillespie <billg at metrumrg.com> wrote:
> I currently use lattice functions to produce multiple pages of plots using
> the "layout" argument to specify the number of rows and columns of panels,
> e.g.,
>
> xyplot(price ~ carat | clarity, diamonds, layout = c(2, 2))
>
> This results in 2 pages of 4 panels each. "diamonds" is a data.frame
> distributed with ggplot2.
>
> I would like to do the same with ggplot2 but have been unsuccessful. The
> following sequence of statements seemed like a logical way to do it:
> p <- ggplot(diamonds, aes(carat, price))
> p + geom_point() + facet_wrap(~clarity, ncol = 2, nrow = 2)
> But they result in the error statement: "Error in nrow * ncol : non-numeric
> argument to binary operator".
>
> Is facet_wrap or facet_grid capable of producing multiple pages of plots
> and, if so, how?

Not automatically - it's up to you to figure out how to split the
factor levels in pages and then create the appropriate subsets.

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list