如何在 varImpPlot 上设置 x 限制

How to set x limits on varImpPlot

如何更改 varImpPlotrandomForest 包生成的绘图的 x 限制?

如果我尝试

set.seed(4543)
data(mtcars)
mtcars.rf <- randomForest(mpg ~ ., data=mtcars, ntree=1000, keep.forest=FALSE,
                      importance=TRUE)
varImpPlot(mtcars.rf, scale=FALSE, type=1, xlim=c(0,15))

我收到以下错误:

Error in dotchart(imp[ord, i], xlab = colnames(imp)[i], ylab = "", main = if (nmeas == : formal argument "xlim" matched by multiple actual arguments".

这是因为 varImpPlot 定义了它自己的 x 限制,我想,但是如果我想自己设置 x 限制(可能是为了跨地块的一致性),我该如何解决这个问题?

首先,我使用 importance() 提取了值(感谢@dww 的建议)

impToPlot <- importance(mtcars.rf, scale=FALSE)

然后我使用 dotchart() 绘制它们,这允许我手动设置 x 限制(以及我想要的任何其他绘图功能)

dotchart(sort(impToPlot[,1]), xlim=c(0,15), xlab="%IncMSE")