1

我只能用不同的数据集一一得到qq图。。

library(fitdistrplus)


x1<-c(1300,541,441,35,278,167,276,159,126,60.8,160,5000,264.6,379,170,251.3,155.84,187.01,850)
x2<-c(25,500,42,100,10,8.2,76,2.2,7.86,50)
y1<-log10(x1)
y2<-log10(x2)
x1.logis <- fitdist(y1, "logis", method="mle")
x2.logis <- fitdist(y2, "logis", method="mle")
ppcomp(x1.logis, addlegend=FALSE)
ppcomp(x2.logis, addlegend=FALSE)

如何将两个qq图放在同一个坐标系中?

4

1 回答 1

1

使用ggplot2. 您需要从fitdist对象 n 中提取拟合值并创建一个新数据框。使用ggplot2图层从两个数据集中添加拟合值,然后添加 abline。

library(ggplot2)
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)
于 2016-10-21T14:13:26.643 回答