J.Zhang J.Zhang - 3 months ago 19
R Question

Place different QQ plot (with different datasets) in the same coordinate system

I can only get the qq plot one by one with different datasets..


x1.logis <- fitdist(y1, "logis", method="mle")
x2.logis <- fitdist(y2, "logis", method="mle")
ppcomp(x1.logis, addlegend=FALSE)
ppcomp(x2.logis, addlegend=FALSE)

How can i place the two qq plot in same coordinate system?


Use ggplot2. You need to extract your fitted values from the fitdist object n and make a new data frame. Use ggplot2 layers to add the fitted values from the two data sets and then add an abline.

fittedx1 <- data.frame(x = sort(plogis(x1.logis$data,
                                location = x1.logis$estimate[1], 
                                scale = x1.logis$estimate[2])),
                       p = (1:length(x1.logis$data))/length(x1.logis$data))

fittedx2 <- data.frame(x = sort(plogis(x2.logis$data,
                                location = x2.logis$estimate[1], 
                                scale = x2.logis$estimate[2])),
                   p = (1:length(x2.logis$data))/length(x2.logis$data))

fitted <- rbind(fittedx1,fittedx2) #You need to combine the two datasets
#Add a variable that identifies which dataset the values belong to
#Then you can use the col option in ggplot to give each data set its own color!
fitted$set <- c(rep("1", nrow(fittedx1)), rep("2", nrow(fittedx2))) 

#Now plot
ggplot(fitted) +
  geom_point(aes(p, x, col=set), shape=1, size=3) +
  geom_abline(intercept=0, slope=1)