Why `cumsum` doesn't work within groups or facets in ggplot?

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..)),