title: Plot frequency histogram with a 4-level factor using ggplot2
body: <p>I have data that I would like to put into a histogram showing the frequencies within each subset of 4 factors. I would like them to be on the same histogram and in different colors. The ..ncount.. function looks to be the best, but it is normalizing the data to a maximum of 1, while I want the SUM of all of the frequencies within a subset to be equal to 1. Here is the code I have used and the accompanying graphs:</p>
  
  <p>my data file is: "assocID"
  The factor is: "category"
  the continuous variable that I am using for the histogram is : "QGM"</p>
  
  <pre><code>ggplot(assocID,aes(QGM)) + 
      geom_histogram(binwidth=0.1,aes(fill=category,y(..count..)),position="dodge") +
      facet_wrap(~dyad)
  </code></pre>
  
  <p>go <a href="http://imgur.com/sMBPN,enIwl,fQNRJ#0" rel="nofollow">here</a> to see the three output images. I am a new used to stackoverflow so they won't let me post images. I figure the graphs will explain better than the text!</p>
  
  <p>Now if I use <code>(..count..)/sum(..count..)</code> that just divides by the total count, not within subsets</p>
  
  <pre><code>ggplot(assocID,aes(QGM)) + 
      geom_histogram(binwidth=0.1,aes(fill=category,y(..count..)/sum(..count..)),position="dodge") + 
      facet_wrap(~dyad)
  </code></pre>
  
  <p>finally the ncount one doesn't seem to do it either.</p>
  
  <pre><code>ggplot(assocID,aes(QGM)) + 
      geom_histogram(binwidth=0.1,aes(fill=category,y(..ncount..)),position="dodge") + 
      facet_wrap(~dyad)
  </code></pre>
  
  <p>basically I want to show a histogram of frequencies WITHIN each factor of the variable "category"</p>
  
  <p>Any help would be much appreciated!</p>