title: Color histogram bins by majority class
body: <p>I've written a useful function to color histogram bars by the majority class in each bar:</p>
  
  <pre><code>color_hist &lt;- function(x, cats, ...){
    hist &lt;- hist(x, plot=FALSE, ...)
    cuts &lt;- cut(x, breaks=hist$breaks)
  
    color = apply(table(cuts, cats), 1, which.max)
  
    hist(x, col=color,...)
  }
  
  color_hist(iris[,4], iris[,5])
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/i9LbS.png" alt="color hist"></p>
  
  <p>I'd like to replicate the behavior of <code>hist()</code> as much as possible, but I can't figure out how to pass the title and x label from the original histogram to the colorized one:</p>
  
  <p><img src="https://i.stack.imgur.com/BzqKs.png" alt="hist2"></p>
  
  <p>I'd like the new histogram to have the same default title/xlabels as the old histogram, and I'd also like to pass through any other user-specified parameters. Can anyone help me solve this problem, or improve this function in any other way?</p>
  
  <p>(It would also be cool if I could get the colors to blend into each other, depending on the class percentages...)</p>