R语言使用ggplot2可视化互相覆盖的直方图实战(Overlaying histograms)

wuchangjian2021-11-03 08:32:20编程学习

R语言使用ggplot2可视化互相覆盖的直方图实战(Overlaying histograms)

dat <- data.frame(xx = c(runif(100,20,50),runif(100,40,80),runif(100,0,30)),yy = rep(letters[1:3],each = 100))

ggplot(dat,aes(x=xx)) + 
    geom_histogram(data=subset(dat,yy == 'a'),fill = "red", alpha = 0.2) +
    geom_histogram(data=subset(dat,yy == 'b'),fill = "blue", alpha = 0.2) +
    geom_histogram(data=subset(dat,yy == 'c'),fill = "green", alpha = 0.2)

参考:R

参考:Overlaying histograms with ggplot2 in R

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。