title: How do I color by factors of a categorical variable for faceted barplots?
body: <p>My question relates to plots in ggplot. Running the code below each image should work if you load the "diamonds" dataset that comes with ggplot2.</p>
  
  <p>I am trying to generate a graph like this:</p>
  
  <p><img src="https://i.stack.imgur.com/o3sXk.png" alt="Barplot of colors faceted by cut"></p>
  
  <pre><code>library(ggplot2)
  
  #First plot
  p1 &lt;- ggplot(diamonds, aes(color)) + geom_bar(aes(group = cut, y = ..density..))
  p1 &lt;- p1 + facet_wrap(~cut)
  p1
  </code></pre>
  
  <p>but I want to color each bar in each facet by factor, like in this plot:</p>
  
  <p><img src="https://i.stack.imgur.com/yJtJM.png" alt="Color example"></p>
  
  <pre><code>#Second plot
  p2 &lt;- ggplot(diamonds, aes(color)) + geom_bar(aes( y = ..density.., fill = color)) 
  p2 &lt;- p2 + facet_wrap(~cut)
  p2
  </code></pre>
  
  <p>The problem is that "group =" and "fill=" appear to interfere with each other when I attempt to call them both; ggplot seems to ignore the "fill" command when "group" is also called.</p>
  
  <p>The call to group is important because it forces the y-axis to scale for each facet, so that densities within each facet add up to 1. However, I'd like to be able to visually distinguish between groups easily using fill colors.</p>
  
  <p>How can I work around this? </p>