R 如何使ggplot ecdf以填充背景进行打印

R 如何使ggplot ecdf以填充背景进行打印,r,plot,ggplot2,R,Plot,Ggplot2,我试图让我的经验累积密度曲线填充背景,但似乎无法继续 我尝试了以下两种方法,第一种似乎改变了曲线的alpha,而不是填充 ggplot( myDataFrame , aes( x=myVariable , fill=myFactor ) ) + geom_step ( stat="ecdf" , aes( colour = myFactor ) , alpha=1 ) + coord_cartesian( xlim

我试图让我的经验累积密度曲线填充背景,但似乎无法继续

我尝试了以下两种方法,第一种似乎改变了曲线的alpha,而不是填充

ggplot( myDataFrame , aes( x=myVariable , fill=myFactor ) )                       +
geom_step      ( stat="ecdf" , aes( colour = myFactor  ) , alpha=1 )              +
coord_cartesian( xlim = c( 0 , quantile( myDataFrame$myVariable , prob=0.99 ) ) ) +
facet_grid     ( myFactor ~ . , scales="free_y" )
第二种似乎与上述情况相同

ggplot( myDataFrame , aes( x=myVariable , fill=myFactor ) )                       +
stat_ecdf      ( aes( colour = myFactor ) ,alpha=0.2 )                            +
coord_cartesian( xlim = c( 0 , quantile( myDataFrame$myVariable , prob=0.99 ) ) ) +
facet_grid     ( myFactor ~ . , scales="free_y" )
我也不知道它是否会在提前饱和的因子水平的整个xlim中填满100%

像这样的事

library(ggplot2)
set.seed(1)
df <- data.frame(var=c(rnorm(1000),rpois(1000,25),rgamma(1000,25)),
                 fact=rep(c("N","P","G"),each=1000))
ggplot(df,aes(x=var,fill=fact))+
  stat_ecdf(aes(ymin=0,ymax=..y..),geom="ribbon")+
  stat_ecdf(geom="step")+
  facet_grid(fact~.,scales="free_y")

库(ggplot2)
种子(1)

您能解释一下ymax中的
.y..
符号吗?我以前在ggplot中没有看到过这一点,stat_ecdf文档中也没有提到这一点。我使用了您的示例代码,它只适用于该参数。谢谢