# [R] overlaying frequency histograms or density plots in R

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Thu Feb 25 10:11:01 CET 2021

```Hi.

My understanding is that position dodge places each bar in each histogram
beside each other and position stack places all respective bars atop each
other.

Relative frequency is something different.

Cheers

Petr

From: Bogdan Tanasa <tanasa using gmail.com>
Sent: Thursday, February 25, 2021 8:43 AM
To: PIKAL Petr <petr.pikal using precheza.cz>
Cc: r-help <r-help using r-project.org>
Subject: Re: [R] overlaying frequency histograms or density plots in R

Thanks a lot Petr !

shall i uses "dodge" also for the RELATIVE FREQUENCY HISTOGRAMS :

p <- ggplot(iris, aes(x=Sepal.Length, y=..count../sum(..count..)*100,
colour=Species))
p+geom_histogram(position="dodge")

or is there any other way to display the RELATIVE FREQUENCY HISTOGRAMS ?

thanks again !

On Wed, Feb 24, 2021 at 11:00 PM PIKAL Petr <petr.pikal using precheza.cz
<mailto:petr.pikal using precheza.cz> > wrote:

Hi

You should use position dodge.

p <- ggplot(iris, aes(x=Sepal.Length, colour=Species))
p+geom_density()
p <- ggplot(iris, aes(x=Sepal.Length, y=..density.., colour=Species))
p+geom_histogram(position="dodge")

Cheers
Petr
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org
> <mailto:r-help-bounces using r-project.org> > On Behalf Of Bogdan Tanasa
> Sent: Wednesday, February 24, 2021 11:07 PM
> To: r-help <r-help using r-project.org <mailto:r-help using r-project.org> >
> Subject: [R] overlaying frequency histograms or density plots in R
>
> Dear all, we do have a dataframe with a FACTOR called EXP that has 3
LEVELS ;
>
>     VALUE  EXP
> 1 1639742 DMSO
> 2 1636822 DMSO
> 3 1634202 DMSO
>
> shall i aim to overlay the relative frequency histograms, or the density
> histograms for the FACTOR LEVELS,
>
> please would you let me know why the following 2 pieces of R code show
> very different results :
>
> ggplot(pp_ALL, aes(x=VALUE, colour=EXP)) + geom_density()
>
> versus
>
> ggplot(data=pp_ALL) +
>        geom_histogram(mapping=aes(x=VALUE, y=..density.., colour=EXP),
>  bins=1000)
>
> thanks,
>
> bogdan
>
> ps : perhaps i shall email to the folks on ggplot2 mailing list too ...
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org <mailto:R-help using r-project.org>  mailing list -- To
> UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help