title: r percentage by bin in histogram ggplot
body: <p>I have a data set like this -></p>
  
  <pre><code>library(ggplot2)
  
  response &lt;- c("Yes","No")
  gend &lt;- c("Female","Male")
  
  purchase &lt;- sample(response, 20, replace = TRUE)
  gender &lt;- sample(gend, 20, replace = TRUE)
  
  df &lt;- as.data.frame(purchase)
  df &lt;- cbind(df,gender)
  </code></pre>
  
  <p>so <code>head(df)</code> looks like this -> </p>
  
  <pre><code>  purchase gender
  1      Yes Female
  2       No   Male
  3       No Female
  4       No Female
  5      Yes Female
  6       No Female
  </code></pre>
  
  <p>Also, so you can validate my examples, here is <code>table(df)</code> for my particular sampling.<br>
    <em>(please don't worry about matching my percentages)</em></p>
  
  <pre><code>         gender
  purchase Female Male
       No       6    3
       Yes      4    7
  </code></pre>
  
  <p>I want a "histogram" showing Gender, but split by Purchase.
  I have gone this far -> </p>
  
  <pre><code>ggplot(df) + 
         geom_bar(aes(y = (..count..)/sum(..count..)),position = "dodge") + 
         aes(gender, fill = purchase)
  </code></pre>
  
  <p>which generates -></p>
  
  <p>histogram with split bins, by percentage, but not the aggregate level I want
  <img src="https://i.stack.imgur.com/BVw3s.jpg" alt="histogram with split bins, by percentage, but not the aggregate level I want"></p>
  
  <p>The Y axis has Percentage as I want, but it has each bar of the chart as a percentage of the whole chart. 
  What I want is the two "Female" bars to each be a percentage of there respective "Purchase". So in the chart above I would like four bars to be, 
  <code>66%, 36%, 33%, 64%</code>
  , in that order. </p>
  
  <p>I have tried with geom_histogram to no avail. I have checked SO, searched, ggplot documentation, and several books.</p>
  
  <p>Regarding the suggestion to look at the previous question about facets; that does work, but I had hoped to keep the chart visually as it is above, as opposed to split into "two charts". So...</p>
  
  <p>Anyone know how to do this?</p>
  
  <p>Thanks.</p>