hadley/ggplot2 — Issue #358: Allow facets to be specified by an explicit vector rather than only the name of a column in a dataset
Author: jiho
Created: 2012-01-18 09:01:19+00:00
State: open

It is possible to do

d <- data.frame(x=runif(10),
y=runif(10),
a=c("foo", "bar", "foo", "foo", "bar", "foo", "bar", "foo", "bar", "bar")
)
ggplot() + geom_point(aes(x=d$x, y=d$y))

so one expects to be able to do

ggplot() + geom_point(aes(x=d$x, y=d$y)) + facet_wrap(d$a)

which is currently impossible because `facet_*` takes a formula as argument and requires the elements of the formula to be fetched from a data set. It would be a nice addition if facetting could take an actual vector of categories as argument (the same way `d*ply` functions can take formulas or actual variables as input to split the data.frame by). Of course this can create hedge cases when the vector specifying the facets is completely different from the data source of the layers. But I guess that, to achieve this:

ggplot() + geom_point(aes(x=d$x, y=d$y))

somewhere, ggplot creates a temporary data set for the point layer. One would just have to add columns with the facetting variables, recycling them as necessary (just as it happens when creating a data.frame).