Hi,

I need to add theoretical(normal) CDF to eCDF in one plot and later in subgroups.

I followed this:

https://stats.stackexchange.com/questions/153725/plotting-a-ecdf-in-r-and-overlay-cdf

but these code:

```
library(ggplot2)
set.seed(235)
x<-rgamma(40,2,scale=3)
p<-qplot(x,stat="ecdf",geom="step")+theme_bw()
p<-p+stat_function(fun=pgamma,color="blue",args=list(shape=2,scale=3))
p<-p+labs(title="ECDF and theoretical CDF")
p
```

gives me an error:

```
Error: Aesthetics must be either length 1 or the same as the data (1): x
Run `rlang::last_error()` to see where the error occurred.
```

I do not know why ?

Additionally I have read this:

https://stackoverflow.com/questions/24818995/ggplot2-ecdf-faceting-for-subsets-overall-ecdf-in-each-panel?rq=1

```
ggplot(diamonds) +
stat_ecdf(aes(x=carat, colour = color)) +
stat_ecdf(data=diamonds[, names(diamonds) != "color"], aes(x=carat), lwd=1, linetype="dotted") +
facet_wrap(~color, ncol=4)
```

and I would like to add normal standard CDF in each panel (apart from those two drawn already).

How do I do this ? Any ideas will be greatly appreciated.

My ideal results will be like here:

https://bjlkeng.github.io/posts/the-empirical-distribution-function/

when every distribution has got nice eCDF, normal CDF (dotted red line) and confidence bands, as well.

But this is not done in R.