Borrowing example from Plotting cumulative counts in ggplot2
x <- data.frame(A=replicate(200,sample(c("a","b","c"),1)),X=rnorm(200))
ggplot(x,aes(x=X,color=A)) + stat_bin(aes(y=cumsum(..count..)),geom="step")
As you can see, cumsum
work across groups & facets. I am wondering why it does that? Clearly ..count..
is done within groups, why cumsum
is not when applied on to ..count..
? Does ggplot internally cat all ..count..
into a vector and then apply cumsum
to it?
How to correctly resolve it without pre processing, e.g. using plyr
?
And I don't mind geom
is not step
, it can be line
or even bar
as long as the graph is a cumulative plot.