[R] how to overlay two histograms

Rasmus Liland jr@| @end|ng |rom po@teo@no
Fri Sep 18 01:11:23 CEST 2020


On 2020-09-17 17:01 -0500, Ana Marija 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.

Dear Ana,

you need to specify stat="identity" [1], 
like so:

	mapping <- ggplot2::aes(
	  x=CHR,
	  y=counts,
	  fill=name)
	p <-
	  ggplot2::ggplot() +
	  ggplot2::geom_bar(
	    data=d,
	    mapping = mapping,
	    position="dodge",
	    stat="identity")

Best,
Rasmus

[1] https://stackoverflow.com/questions/61068031/error-stat-count-can-only-have-an-x-or-y-aesthetic

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200918/8f6f13a4/attachment.sig>


More information about the R-help mailing list