fitdist
我用包中的函数拟合了正态分布fitdistrplus
。使用denscomp
, qqcomp
,我们可以分别绘制, , , 和cdfcomp
,如下所示。ppcomp
histogram against fitted density functions
theoretical quantiles against empirical ones
the empirical cumulative distribution against fitted distribution functions
theoretical probabilities against empirical ones
set.seed(12345)
df <- rnorm(n=10, mean = 0, sd =1)
library(fitdistrplus)
fm1 <-fitdist(data = df, distr = "norm")
summary(fm1)
denscomp(ft = fm1, legendtext = "Normal")
qqcomp(ft = fm1, legendtext = "Normal")
cdfcomp(ft = fm1, legendtext = "Normal")
ppcomp(ft = fm1, legendtext = "Normal")
我对制作这些fitdist
情节非常感兴趣ggplot2
。MWE如下:
qplot(df, geom = 'blank') +
geom_line(aes(y = ..density.., colour = 'Empirical'), stat = 'density') +
geom_histogram(aes(y = ..density..), fill = 'gray90', colour = 'gray40') +
geom_line(stat = 'function', fun = dnorm,
args = as.list(fm1$estimate), aes(colour = 'Normal')) +
scale_colour_manual(name = 'Density', values = c('red', 'blue'))
ggplot(data=df, aes(sample = df)) + stat_qq(dist = "norm", dparam = fm1$estimate)
我怎样才能开始制作这些fitdist
情节ggplot2
?