我使用fitdistrplus软件包中的fitdist函数来获得最优分布,并绘制ppcomp图,我使用?fitdistrplus的示例代码来替换我的数据和代码。
data(groundbeef)
serving <- groundbeef$serving
fitW <- fitdist(serving, "weibull")
fitg <- fitdist(serving, "gamma")
fitln <- fitdist(serving, "lnorm")
ppcomp(list(fitW, fitg, fitln), legendtext=c("Weibull", "gamma", "lognormal"))

到目前一切尚好!但是看看图片的左下角,有一些空间,或者轴不是从零开始的!
所以我用谷歌搜索了一下,发现了两种方法:一种是基础图中的方法,使用的是xaxs和yaxs。
set.seed(1234)
x <- runif(100, min=0, max=100)
y <- runif(100, min=0, max=100)
plot(x,y,xaxs="i",yaxs="i",xlim=c(0,100),ylim=c(0,100))

使用了ggplot2中的另一种方法expand=c(0,0)。
df <- data.frame(x=x,y=y)
ggplot(df,aes(x,y)) + geom_point() + scale_x_continuous(expand = c(0,0)) + scale_y_continuous(expand = c(0,0))

所以我试着用这两种方法来绘制ppcomp图,
ppcomp(list(fitW, fitg, fitln), legendtext=c("Weibull", "gamma", "lognormal"),xaxs="i",yaxs="i")但出现错误:
Error in legend(x = xlegend, y = ylegend, bty = "n", legend = legendtext, :
unused arguments (xaxs = "i", yaxs = "i")那么,我应该做什么才能在没有错误的情况下完成目标,或者什么是正确的代码?
发布于 2016-07-04 16:28:01
问题似乎是ppcomp中的...参数(它接受额外的参数)同时提供给plot和legend,而legend不知道如何处理xaxs。
选项包括:
1)使用xaxs运行ppcomp,这将绘制绘图,然后单独添加legend。
2)使用fix(ppcomp)从legend命令中删除...。
3)重新编码ppcomp以使用ggplot,并根据需要设置选项。
https://stackoverflow.com/questions/38177612
复制相似问题