如何设置 varImpPlot 的 x 限制

Jes*_*yer 2 plot r random-forest

我怎样才能改变由x产生的情节的限制varImpPlotrandomForest

如果我尝试

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))
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

dotchart(imp[ord, i], xlab = colnames(imp)[i], ylab = "", main = if (nmeas == : 形式参数“xlim”与多个实际参数匹配)中出现错误”。

我认为这是因为varImpPlot定义了它自己的x限制,但是如果我想自己设置 x 限制(也许是为了图之间的一致性),我该如何解决这个问题?

Jes*_*yer 5

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

impToPlot <- importance(mtcars.rf, scale=FALSE)
Run Code Online (Sandbox Code Playgroud)

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

dotchart(sort(impToPlot[,1]), xlim=c(0,15), xlab="%IncMSE")
Run Code Online (Sandbox Code Playgroud)

具有手动 x 轴的不同重要性的点图