在 R 中使用 fitdistrplus 正确显示 4 面板分布图的图例

Properly display the legend of a 4 panel distribution plot with fitdistrplus in R

提问人:Hack-R 提问时间:11/3/2015 最后编辑:Hack-R 更新时间:11/4/2015 访问量:606

问:

我正在 R 中使用该包,并试图制作一个漂亮的 4 面板分布图,就像作者发表的论文(J. of Statistical Software,第 64 卷,第 4 期)一样:fitdistrplus

Delignette-Muller et al., 2015

但是,当我使用他们在论文中提供的相同代码时,与不同颜色编码的线/曲线相关的文本值只是任意放置,您无法分辨哪种颜色对应于哪个系列:

par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw, fln, fg), legendtext = plot.legend)
qqcomp(list(fw, fln, fg), legendtext = plot.legend)
cdfcomp(list(fw, fln, fg), legendtext = plot.legend)
ppcomp(list(fw, fln, fg), legendtext = plot.legend)

Real world version

我也尝试了这个选项。, xlegend = "bottomright"

R

评论


答:

4赞 Calvin 11/4/2015 #1

如果希望图例在每个绘图中可见,可以手动操作位置。下面提供了一些示例代码。此外,使用缩放图例将避免图例与绘图的大部分重叠。确切的图例位置将基于您的数据。cex

library(fitdistrplus)
x <- exp(rnorm(100,0,1))

fw <- fitdist(x,distr="weibull")
fln <- fitdist(x,distr="lnorm")
fg <- fitdist(x,distr="gamma")


par(mfrow = c(2, 2))
plot.legend <- c("Weibull", "lognormal", "gamma")
denscomp(list(fw, fln, fg)
         , legendtext = plot.legend
         ,xlegend=10
         ,ylegend=0.5
         ,cex=0.7)
qqcomp(list(fw, fln, fg)
       , legendtext = plot.legend
       ,xlegend=8
       ,ylegend=6
       ,cex=0.7)
cdfcomp(list(fw, fln, fg)
        , legendtext = plot.legend
        ,xlegend=8
        ,ylegend=0.3
        ,cex=0.7)
ppcomp(list(fw, fln, fg)
       , legendtext = plot.legend
       ,xlegend=0.7
       ,ylegend=0.3
       ,cex=0.7)

enter image description here