[R] ggplot2: proper use of facet_grid inside a function

hadley wickham h.wickham at gmail.com
Mon Oct 5 15:56:58 CEST 2009


> Whether or not what follows is to be recommended I don't know, but it
> seems to work,
>
> p <- ggplot(diamonds, aes(carat, ..density..)) +
>  geom_histogram(binwidth = 0.2)
>
> x = quote(cut)
> facets = facet_grid(as.formula(bquote(.~.(x))))
> p + facets

That's what I'd recommend.  You can also just do

facets <- facet_grid(paste(". ~ ", var))

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




More information about the R-help mailing list