title: Plotting multiple conditioned histograms on the same page in R
body: <p>SO I am trying to plot multiple conditioned histograms in one page. I have three numeric predictors, AFE, ZCR, and ACC, and they need to be conditioned on class either 0 or 1.</p>
  
  <p>When I do it for a single variable:</p>
  
  <pre><code>histogram(myData.toplot$Class ~ myData.toplot$AFE | myData.toplot$Class)
  </code></pre>
  
  <p>It works fine. Now I want to put all three of them in the same plot. I tried this:</p>
  
  <pre><code>x = histogram(myData.toplot$Class ~ myData.toplot$AFE | myData.toplot$Class)
  y = histogram(myData.toplot$Class ~ myData.toplot$ZCR | myData.toplot$Class)
  z = histogram(myData.toplot$Class ~ myData.toplot$ACC | myData.toplot$Class)
  print(x, position=c(0, 0, 1, .35), more=TRUE)
  print(y, position=c(0, .3, 1, .65), more=TRUE)
  print(z, position=c(0, .6, 1, .95))
  </code></pre>
  
  <p>And that works, but, I don't want to have to specify the exact placing c, as the number of predictors grows. So instead, I tried the layout function:</p>
  
  <pre><code>histogram( myData.toplot$Class ~ myData.toplot$AFE +myData.toplot$ZCR +myData.toplot$ACC | myData.toplot$Class ,layout=c(1,3),data = myData.toplot)
  </code></pre>
  
  <p>However, that is very unsatisfactory. It doesn't know how to condition on the classes properly. How can I use the lattice package to plot three panels of conditioned histograms in one page?</p>
  
  <p>There is another way to do histograms:</p>
  
  <pre><code>set.seed(42)
  p1 &lt;- hist(rnorm(500,4))                     # centered at 4
  p2 &lt;- hist(rnorm(500,6))                     # centered at 6
  plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10))  # first histogram
  plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T)  # second
  </code></pre>
  
  <p>However when I add:</p>
  
  <pre><code>par(mfrow=c(3,1))  ##this is what I added
  set.seed(42)
  p1 &lt;- hist(rnorm(500,4))                     # centered at 4
  p2 &lt;- hist(rnorm(500,6))                     # centered at 6
  plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10))  # first histogram
  plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T)  # second
  
  set.seed(41)
  p11 &lt;- hist(rnorm(500,4))                     # centered at 4
  p21 &lt;- hist(rnorm(500,6))                     # centered at 6
  plot( p11, col=rgb(0,0,1,1/4), xlim=c(0,10))  # first histogram
  plot( p21, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T)  # second
  
  set.seed(40)
  p12 &lt;- hist(rnorm(500,4))                     # centered at 4
  p22 &lt;- hist(rnorm(500,6))                     # centered at 6
  plot( p12, col=rgb(0,0,1,1/4), xlim=c(0,10))  # first histogram
  plot( p22, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T)  # second
  </code></pre>
  
  <p>I get two pages, one with p1, p2, and the combo of p1 and p2, and another page with p11, p12, and the combo of p11 and p12...etc I want to use the par() command to simply put the combos in three rows. How can I do that?</p>