I need to add theoretical(normal) CDF to eCDF in one plot and later in subgroups.
I followed this:
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:
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:
when every distribution has got nice eCDF, normal CDF (dotted red line) and confidence bands, as well.
But this is not done in R.