繁体   English   中英

为什么在使用 plotstyle="ggplot" 时 qqcomp 函数中没有显示任何点?

[英]Why aren't any points showing up in the qqcomp function when using plotstyle="ggplot"?

我想在一个图中比较不同分布与我的数据的拟合。 fitdistrplus包中的qqcomp函数几乎完全符合我的要求。 然而,我唯一的问题是它主要是使用基本 R 绘图编写的,而我的所有其他绘图都是用ggplot2编写的。 我基本上只是想自定义qqcomp图,使其看起来像是在ggplot2ggplot2

从文档( https://www.rdocumentation.org/packages/fitdistrplus/versions/1.0-14/topics/graphcomp )我知道这完全有可能通过设置plotstyle="ggplot" 但是,如果我这样做,即使在没有 plotstyle 参数的情况下它也能完美运行,情节上也不会显示任何点。 这是一个可视化我的问题的小例子:

library(fitdistrplus)
library(ggplot2)

set.seed(42)
vec <- rgamma(100, shape=2)

fit.norm <- fitdist(vec, "norm")
fit.gamma <- fitdist(vec, "gamma")
fit.weibull <- fitdist(vec, "weibull")

model.list <- list(fit.norm, fit.gamma, fit.weibull)

qqcomp(model.list)

这给出了以下输出:

baseR qqplot

虽然这个:

qqcomp(model.list, plotstyle="ggplot")

给出以下输出:

ggplot qqplot

为什么积分不显示? 我在这里做错了什么还是这是一个错误?

编辑:

所以我还没有弄清楚为什么这不起作用,但是有一个非常简单的解决方法。 函数调用qqcomp(model.list, plotstyle="ggplot")仍然返回一个 ggplot 对象,其中包括用于绘制绘图的数据。 使用该数据,人们可以轻松编写自己的绘图函数,该函数完全符合您的要求。 它不是很优雅,但是直到有人发现它为什么没有按预期工作之前,我只会使用这种方法。

我能够重现您的错误,确实,这真的很有趣。 也许,您应该联系此包的开发人员以提及此错误。

否则,如果您想使用ggplotstat_qq重现此 qqplot,请传递相应的分布函数和相关参数(存储在 $estimate 中):

library(ggplot2)
df = data.frame(vec)
ggplot(df, aes(sample = vec))+
  stat_qq(distribution = qgamma, dparams = as.list(fit.gamma$estimate), color = "green")+
  stat_qq(distribution = qnorm, dparams = as.list(fit.norm$estimate), color = "red")+
  stat_qq(distribution = qweibull, dparams = as.list(fit.weibull$estimate), color = "blue")+
  geom_abline(slope = 1, color = "black")+
  labs(title = "Q-Q Plots", x = "Theoritical quantiles", y = "Empirical quantiles")

在此处输入图片说明

希望它会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM