我正在尝试在两条曲线下阴影区域。我要得到完全相同的地块(无阈值虽然)在以前的帖子,与我想要使用的唯一的区别geom_line(),而不是stat_density()。有什么办法吗?提前致谢。
我已经尝试了该帖子中建议的内容,但使用时不起作用geom_line()。另外,我尝试了一些不同的方法,但这并不是我想要的,因为我想为不同的组使用不同的颜色进行着色。这是初始代码:
library(ggplot2)
x <- seq(0,1,0.005)
y1 <- dbeta(x,3,3)
data1<-data.frame('x'=x,'y'=y1)
data1$group<-1
y2 <- dbeta(x,10,4)
data2<-data.frame('x'=x,'y'=y2)
data2$group<-2
data<-rbind(data1, data2)
ggplot(data, aes(x=x, y=y, group=group, col=group, fill=group)) + geom_line(size=1) +geom_ribbon(data=subset(data,x>0 &x<1),aes(x=x,ymax=y),ymin=0, fill="green4",alpha=0.3)
Run Code Online (Sandbox Code Playgroud)
如果上述链接不起作用:ggplot2阴影曲线下的阴影区域(按组)