在R

时间:2018-10-30 10:40:28

标签: r ggplot2 histogram

关于this问题,我想产生一个重叠的直方图,其中每组数据通过除以该组计数的总和来缩放。

从链接的问题中借用示例和kohske的答案,我试图结合使用y = stat(count / sum(count))group = yy来缩放直方图,但是整个数据集除以sum(count) ,而不是每个组单独。

dat <- data.frame(xx = c(runif(100,20,50),runif(100,40,80),runif(30,0,30)),yy = rep(letters[1:3],c(100,100,30)))
ggplot(dat, aes(x=xx, y = stat(count / sum(count)), fill=yy, group=yy)) + 
    geom_histogram(alpha=0.2, position="identity")

overlapping histogram plot not normalising by group

如何按yy组而不是整个数据集进行缩放?我想要一个图,其中每个条形图代表该组在xx范围内的百分比,以比较a,b和c中的分布形状,而不是绝对计数。

0 个答案:

没有答案
相关问题