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 am really not sure what you are doing but will this help?
library(ggplot2)
set.seed(235)
y <- rgamma(40, 2, scale = 3)
x <- 1:length(x)
dat1 <- data.frame(x, y)
p <- ggplot(dat1, aes(y, x)) +geom_step()
p <- p + stat_function(fun = pgamma,
color = "blue",
args = list(shape = 2, scale = 3))
p <- p + labs(title = "ECDF and theoretical CDF")
p
I think your first problem is that your x is a vector and ggplot requires a data.frame. I then used ggplot() rather than qplot() as qplot() is pretty archaic and I think better in ggplot().
Yes , that vas very helpful, thank you and @jrkrideau thank you too.
I am trying to learn that eCDF as an alternative to histogram with density curve exploring data and to check
the data from departure from eg. normal distribution and other distributions.
Thanks again.