title: Plotting cumulative counts in ggplot2
body: <p>There are some posts about plotting cumulative densities in ggplot. I'm currently using the accepted answer from <a href="https://stackoverflow.com/questions/3544002/easier-way-to-plot-the-cumulative-frequency-distribution-in-ggplot">Easier way to plot the cumulative frequency distribution in ggplot?</a> for plotting my cumulative counts. But this solution involves pre-calculating the values beforehand.</p>
  
  <p>Here I'm looking for a pure ggplot solution. Let's show what I have so far:</p>
  
  <pre><code>x &lt;- data.frame(A=replicate(200,sample(c("a","b","c"),1)),X=rnorm(200))
  </code></pre>
  
  <h2>ggplot's <code>stat_ecdf</code></h2>
  
  <p>I can use ggplot's <code>stat_ecdf</code>, but it only plots cumulative densities:</p>
  
  <pre><code>ggplot(x,aes(x=X,color=A)) + geom_step(aes(y=..y..),stat="ecdf")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/bvrpA.png" alt="enter image description here"></p>
  
  <p>I'd like to do something like the following, but it doesn't work:</p>
  
  <pre><code>ggplot(x,aes(x=X,color=A)) + geom_step(aes(y=..y.. * ..count..),stat="ecdf")
  </code></pre>
  
  <h2><code>cumsum</code> and <code>stat_bin</code></h2>
  
  <p>I found an idea about using <code>cumsum</code> and <code>stat_bin</code>:</p>
  
  <pre><code>ggplot(x,aes(x=X,color=A)) + stat_bin(aes(y=cumsum(..count..)),geom="step")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7mEV6.png" alt="enter image description here"></p>
  
  <p>But as you can see, the next color doesn't start at <code>y=0</code>, but where the last color ended.</p>
  
  <h1>What I ask for</h1>
  
  <p>What I'd like to have from best to worst:</p>
  
  <ol>
  <li><p>Ideally a simple fix to the not working</p>
  
  <pre><code>ggplot(x,aes(x=X,color=A)) + geom_step(aes(y=..y.. * ..count..),stat="ecdf")
  </code></pre></li>
  <li><p>A more complicated way to use <code>stat_ecdf</code> with counts.</p></li>
  <li>Last resort would be to use the <code>cumsum</code> approach, since it gives worse (binned) results.</li>
  </ol>