Normalizing y-axis in histograms in R ggplot to proportion
As of the latest and greatest ggplot2 version 3.0.0, the format has changed. Now you can wrap the y
value in stat()
rather than messing with ..
stuff.
ggplot(mydataframe, aes(x = value)) +
geom_histogram(aes(y = stat(count / sum(count))))
Note that ..ncount..
rescales to a maximum of 1.0, while ..count..
is the non scaled bin count.
ggplot(mydataframe, aes(x=value)) +
geom_histogram(aes(y=..count../sum(..count..)))
Which gives: