简体   繁体   English

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

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

I want to compare the fit of different distributions to my data in a single plot.我想在一个图中比较不同分布与我的数据的拟合。 The qqcomp function from the fitdistrplus package pretty much does exactly what I want to do. fitdistrplus包中的qqcomp函数几乎完全符合我的要求。 The only problem I have however, is that it's mostly written using base R plot and all my other plots are written in ggplot2 .然而,我唯一的问题是它主要是使用基本 R 绘图编写的,而我的所有其他绘图都是用ggplot2编写的。 I basically just want to customize the qqcomp plots to look like they have been made in ggplot2 .我基本上只是想自定义qqcomp图,使其看起来像是在ggplot2ggplot2

From the documentation ( https://www.rdocumentation.org/packages/fitdistrplus/versions/1.0-14/topics/graphcomp ) I get that this is totally possible by setting plotstyle="ggplot" .从文档( https://www.rdocumentation.org/packages/fitdistrplus/versions/1.0-14/topics/graphcomp )我知道这完全有可能通过设置plotstyle="ggplot" If I do this however, no points are showing up on the plot, even though it worked perfectly without the plotstyle argument.但是,如果我这样做,即使在没有 plotstyle 参数的情况下它也能完美运行,情节上也不会显示任何点。 Here is a little example to visualize my problem:这是一个可视化我的问题的小例子:

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)

This gives the following output:这给出了以下输出:

baseR qqplot

While this:虽然这个:

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

gives the following output:给出以下输出:

ggplot qqplot

Why are the points not showing up?为什么积分不显示? Am I doing something wrong here or is this a bug?我在这里做错了什么还是这是一个错误?

EDIT:编辑:

So I haven't figured out why this doesn't work, but there is a pretty easy workaround.所以我还没有弄清楚为什么这不起作用,但是有一个非常简单的解决方法。 The function call qqcomp(model.list, plotstyle="ggplot") still returns an ggplot object, which includes the data used to make the plot.函数调用qqcomp(model.list, plotstyle="ggplot")仍然返回一个 ggplot 对象,其中包括用于绘制绘图的数据。 Using that data one can easily write an own plot function that does exactly what one wants.使用该数据,人们可以轻松编写自己的绘图函数,该函数完全符合您的要求。 It's not very elegant, but until someone finds out why it's not working as expected I will just use this method.它不是很优雅,但是直到有人发现它为什么没有按预期工作之前,我只会使用这种方法。

I was able to reproduce your error and indeed, it's really intriguing.我能够重现您的错误,确实,这真的很有趣。 Maybe, you should contact developpers of this package to mention this bug.也许,您应该联系此包的开发人员以提及此错误。

Otherwise, if you want to reproduce this qqplot using ggplot and stat_qq , passing the corresponding distribution function and the parameters associated (stored in $estimate):否则,如果您想使用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")

在此处输入图片说明

Hope it will help you.希望它会帮助你。

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

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