title: Combine multiple plots, generated using the "by" R function, in one figure
body: <p>I have a data frame containing multiple numeric columns and one column with different factors. I'd like to produce a unique image containing the plots of the numeric columns, by factor. I tried the following:</p>
  
  <pre><code>varA    &lt;- runif(40)
  varB    &lt;- runif(40)
  varB    &lt;- runif(40)
  varC    &lt;- runif(40)
  
  mainVar &lt;- c(rep('cat', 10), rep('dof', 10), rep('mouse', 10), rep('frog', 10))
  
  plotData &lt;- data.frame(varA, varB, varC, mainVar)
  
  pdf('asd.pdf')
  par(mfrow=c(2,2))
  
  by(plotData, plotData$mainVar, function(x){
  
    par(mfrow=c(1,3))
    boxplot(x$varA)
    boxplot(x$varB)
    boxplot(x$varC)
  
  })
  
  dev.off()
  </code></pre>
  
  <p>It produces a unique pdf, but with a page for every factor.</p>
  
  <p>Instead, I'd like to get something like that (without the red lines):</p>
  
  <p><img src="https://i.stack.imgur.com/CSpqa.png" alt="figure"></p>