23
I am confused about the meaning of the following variants of geom_density in ggplot:
Can someone please explain the difference between these four calls:
geom_density(aes_string(x=myvar))geom_density(aes_string(x=myvar, y=..density..))geom_density(aes_string(x=myvar, y=..scaled..))geom_density(aes_string(x=myvar, y=..count../sum(..count..)))
My understanding is that:
geom_densityalone will produce a density whose area under the curve sums to 1geom_densitywith..density..basically does the same... ?- the
..count../sum(..count..)will normalize the peak heights to be more like a normalized histogram, ensuring that all the heights sum to 1 - the
..count..by itself without the denominator will just multiply each bin by # of items in it - the
..scaled..parameter will make it so the maximum value of the density is 1.
I find ..scaled.. very counterintuitive and have never seen it used if my interpretation of it is correct so I'd like to ignore that. I am mainly looking for a clarification of the differences between geom_density and a kind of normalized density plot, which I am assuming requires the ...count../... argument. thanks.
(Related: Error with ggplot2 mapping variable to y and using stat="bin")