I am learning geom_bar on section 3.7 of r4ds.had.co.nz. I run a code like this:
library(ggplot2)
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))
Then I have this plot:
The point is, if I exclude the "group = 1" part:
library(ggplot2)
ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop..))
The plot will be wrong,
But if I replace group = 1 by group = 2 or group = "x", the plot still looks correct. So I don't quite understand the meaning of group = 1 here and how to use it.
geom_bar(mapping = aes(x = cut, y = after_stat(prop), group=1))
andgeom_bar(mapping = aes(x = cut, y = after_stat(count/sum(count))))
? – Dorman