scale of geom_density

904 views
Skip to first unread message

pharmpk

unread,
Apr 17, 2014, 12:18:13 AM4/17/14
to ggp...@googlegroups.com
Hello,

I recently plotted using geom_density and geom_histogram(aes(value,y=..density..)). The scale is a lot bigger than 1. My understanding is that the scale of geom_density or geom_histogram(aes(value,y=..density..)) should be between 0 and 1, because density calculates count/sum(count). Am I missing something here? Thanks for considering the help!

Xiaoyu

Dennis Murphy

unread,
Apr 17, 2014, 2:29:32 PM4/17/14
to pharmpk, ggplot2
No. The *integral* of the density is between 0 and 1, but the density
itself is not constrained to be in (0, 1). This is a common misnomer.

For an obvious counterexample, consider the following densities:
* Uniform(0, 1)
* Uniform(0, 0.5)
* Uniform(0, 0.01)

If a random variable X has a Uniform(a, b) distribution, its density is
f(x) = 1/(b - a) for a <= x <= b
and zero otherwise. It is easy from here to show that the latter two
uniforms above have density > 1 over their respective regions of
support, but they are legitimate probability densities, so the total
area under their respective density functions is 1.

Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Xiaoyu Yan

unread,
Apr 17, 2014, 5:19:14 PM4/17/14
to Dennis Murphy, ggplot2
Thanks a lot!
Reply all
Reply to author
Forward
0 new messages