[R] ggplot2 facets as rows and columns

Ben Bolker bolker at ufl.edu
Thu Nov 8 14:52:43 CET 2007


   Does anyone (Hadley??) know if there's a straightforward
way in ggplot2 to get data divided by a single factor to
plot as a rectangular grid of subplots?   So far I've only
been able to get such data plotted as a single row or
single column of skinny subplots.  The code below gives
an example implemented with lattice, and my best
attempt in ggplot2

 cheers
   Ben Bolker

------------
g= rep(1:9,each=50)
means = rnorm(9)
vars = runif(9)
x = rnorm(450,means[g],vars[g])
TDBU = data.frame(system=factor(g),x)

require(lattice)

histogram( ~ x | system, data = TDBU,
          xlab = "LRR Effect Size",type="density",
          panel = function(x, ...) {
            panel.histogram(x, ...)
            panel.densityplot(x,...)
          } ) 

library(ggplot2)
ggplot(TDBU,aes(x=x))+geom_histogram(aes(y=..density..))+
  geom_density()+facet_grid(system~.)


-- 
View this message in context: http://www.nabble.com/ggplot2-facets-as-rows-and-columns-tf4771000.html#a13647294
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list