如何在R中的fitdistrplus包中使坐标轴从零开始

3

我使用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"))

ppcomp

目前为止一切顺利!但是看一下图片左下角,有一些空间,或者坐标轴没有从零开始!

所以我谷歌搜索到两种方法: 在基础图中,使用 xaxsyaxs

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))

expand

所以我尝试使用这两种方法来绘制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")

那么,我应该怎么做才能完成目标而不出错,或者说正确的代码是什么?

1个回答

1
问题似乎在于ppcomp中的...参数(接受额外参数)被同时提供给了plotlegend,而legend不知道如何处理xaxs
选项有:
1)使用xaxs运行ppcomp,这将制作图表,然后单独添加legend
2)使用fix(ppcomp)legend命令中删除...
3)重新编码ppcomp以使用ggplot并根据需要设置选项。

谢谢您,先生。我尝试了选项2,它有效。但是对于选项1,它无效。至于选项3,我不擅长编码,所以没有尝试过。 - Ling Zhang

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接