[R] Fwd: ggplot2 - suggestion for facet_wrap/grid

David Hajage dhajage.r at gmail.com
Wed Dec 3 16:43:04 CET 2008


2008/12/3 hadley wickham <h.wickham at gmail.com>

> Hi David,
>
> > facet_wrap and facet_grid function are both very usefull. But they are
> > perhaps a bit redundant.
>
> I disagree ;)


I was sure :-)


> Conceptually they are rather different: facet_wrap is
> essentially a 1d layout, while facet_grid is a 2d layout.  This has
> implications for how you specify the faceting, how the facets are
> labelled, and how the scales can vary.  While I could probably force
> both into a single function, this is rather against the philosophy of
> ggplot2, which strives towards small objects which only do one thing.
> This tends to make things a little more verbose, but I think it makes
> things easier to understand.
>

OK. I thought that facet_wrap was created to "control" the layout of
facet_grid plot with one-side formula, since a facet_grid plot with one-side
formula should be (almost?) identical with a facet_wrap plot with nrow (or
ncol) = 1.

By the way, I've just test this thing to see the diffences between the two
plots :

d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) +
   xlim(0, 2) + stat_binhex(na.rm = TRUE) + opts(aspect.ratio = 1) ## from
official documentation
d + facet_grid(~ color)
d + facet_wrap(~ color)
d + facet_wrap(~ color, nrow = 1)
Erreur dans rep(list(nullGrob()), nrow * ncol - length(vec)) :
  argument 'times' incorrect

Is this error normal ? facet_wrap must always give a 2d ribbon of panels ?

Thank you very much for your patience.

david


More information about the R-help mailing list