0

I'm fitting data with traditional distributions. I am using qqcomp to plot my fitted distributions in a qqplot. I want to add to this plot also the data qqplot.

I already tried to add them the usual ggplot() way with + getting the message:

q+p Error: Don't know how to add p to a plot

Let's say:

library(ggplot2) 
library(fitdistrplus)

z=rnorm(1000,5,1)+runif(1000,1,2)

fit.w=fitdist(z, "weibull")
fit.ln=fitdist(z, "lnorm")
fit.gam=fitdist(z,"gamma")
fitsc=list(fit.w, fit.ln,fit.gam)

###Comparison of fitted distributions
q=qqcomp  (fitsc, legendtext = plot.legend,plotstyle = "ggplot")
print(q)

enter image description here

###QQplot of the data

z=dataframe(z)

p=ggplot(z,aes(sample=z))+stat_qq()
print(p)

enter image description here

I want to combine the plots q and p into one. I know qqcomp with plotstyle= "ggplot" creates a ggplot object, so I guess there is a way to combine these two plots. Thank you for your help.

rsrjohnson
  • 100
  • 1
  • 8
  • 2
    Does this help: `z1 <- data.frame(z); q + stat_qq(data = z1, aes(sample = z), inherit.aes = FALSE) + coord_fixed()` ? – markus Apr 21 '19 at 18:37
  • What you shared definitively help I just didn't use coord_fixed(). So ```print( q + stat_qq(data = z, aes(sample = z), inherit.aes = FALSE)) ``` did the magic. Thank you so much. – rsrjohnson Apr 21 '19 at 20:03

0 Answers0