【发布时间】:2015-10-17 15:21:19
【问题描述】:
我用fitdistrplus 包中的fitdist 函数拟合了正态分布。使用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")
我非常有兴趣用ggplot2 制作这些fitdist 情节。 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)
如何开始使用ggplot2 制作这些fitdist 绘图?
【问题讨论】:
-
如果这没有附加赏金,我会投票关闭,因为过于广泛。每个图表应该是一个不同的问题(尽管如果您对其中的一个或两个有答案,您可能不需要询问每个图表)。
标签: r plot ggplot2 distribution fitdistrplus