[R] how to overlay two histograms

John Kane jrkr|de@u @end|ng |rom gm@||@com
Fri Sep 18 14:52:28 CEST 2020


Is this what you want?

ggplot(d, aes(counts, fill = name)) +
      geom_bar(stat = "bin", position = "dodge")

Note: You probably should play around with the "bin" width.

On Thu, 17 Sep 2020 at 18:05, Ana Marija <sokovic.anamarija using gmail.com>
wrote:

> Hello,
>
> I am trying to overlay two histograms with this:
>
> p <- ggplot(d, aes(CHR, counts, fill = name)) + geom_bar(position =
> "dodge")
> p
>
> but I am getting this error:
> Error: stat_count() can only have an x or y aesthetic.
> Run `rlang::last_error()` to see where the error occurred.
>
> my data is this:
>
> > d
>    CHR counts name
> 1    1 193554  old
> 2    2 220816  old
> 3    3 174350  old
> 4    4 163112  old
> 5    5 168125  old
> 6    6 182366  old
> 7    7 143023  old
> 8    8 147410  old
> 9    9 122112  old
> 10  10 138394  old
> 11  11 130069  old
> 12  12 124850  old
> 13  13 104119  old
> 14  14  83931  old
> 15  15  72287  old
> 16  16  71550  old
> 17  17  58380  old
> 18  18  76812  old
> 19  19  37040  old
> 20  20  63407  old
> 21  21  33863  old
> 22  22  33812  old
> 23   1 202783  new
> 24   2 252124  new
> 25   3 213337  new
> 26   4 201001  new
> 27   5 207606  new
> 28   6 228133  new
> 29   7 147218  new
> 30   8 177518  new
> 31   9 121276  new
> 32  10 163447  new
> 33  11 158724  new
> 34  12 142183  new
> 35  13 111189  new
> 36  14  83043  new
> 37  15  61063  new
> 38  16  55439  new
> 39  17  32883  new
> 40  18  69135  new
> 41  19  16624  new
> 42  20  48541  new
> 43  21  25479  new
> 44  22  19698  new
>
> Basically I need to show counts per CHR in "old" and "new" side by side.
>
> Please advise,
> Ana
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
John Kane
Kingston ON Canada

	[[alternative HTML version deleted]]



More information about the R-help mailing list