2016-07-05 49 views
0

由於隱私和代碼的可重現性,我擁有超過2000萬個值的大數據,我使用mydata來替換它。傳說中缺少函數ppcomp in package fitdistrplus in R

set.seed(1234) 
mydata <- rlnorm(28000000,3.14,1.3) 

我想找到這已知分佈符合mydata最好的,所以在包裝fitdistrplus功能fitdist被choosen。

library(fitdistrplus) 
fit.lnorm <- fitdist(mydata,"lnorm") 
fit.weibull <- fitdist(mydata, "weibull") 
fit.gamma <- fitdist(mydata, "gamma", lower = c(0, 0)) 
fit.exp <- fitdist(mydata,"exp") 

然後,我用ppcomp函數畫P-P情節幫我選擇最佳擬合的分佈。

library(RColorBrewer) 
tiff("./pplot.tiff",res = 300,compression = "lzw",height = 6,width = 10,units = "in",pointsize = 12) 
ppcomp(list(fit.lnorm,fit.weibull, fit.gamma,fit.exp), fitcol = brewer.pal(9,"Set1")[1:4],legendtext = c("lnorm","weibull", "gamma","exp")) 
dev.off() 

pplot 當然,對數正態分佈適合mydata最好的,但看看劇情的legend,用不同顏色的線註釋丟失,只有文字註釋顯示,我該怎麼辦?

我嘗試了一些數值很少的數據集,它工作。所以大數據導致了這個問題,我應該怎麼做才能使圖例更完美?

+0

在'ppcomp'中的'legend'命令一定有問題,可能需要指定'lty' –

+0

@RichardTelford是的,你說得對,這是一個多麼愚蠢的問題! –

回答

0

很多功能問題可以通過fix(function)完成,這樣我們就可以知道函數是如何工作的。

fix(ppcomp)

我找到傳說中的一些代碼,

if (addlegend) { 
    if (missing(legendtext)) 
     legendtext <- paste("fit", 1:nft) 
    if (!largedata) 
     legend(x = xlegend, y = ylegend, bty = "n", legend = legendtext, 
     pch = fitpch, col = fitcol, ...) 
    else legend(x = xlegend, y = ylegend, bty = "n", legend = legendtext, 
     col = fitcol, ...) 
    } 

然後,我添加lty=1傳說,和它的作品。