gpt4 book ai didi

r - 如何设置 varImpPlot 的 x 限制

转载 作者:行者123 更新时间:2023-12-02 04:09:05 29 4
gpt4 key购买 nike

如何更改由 randomForest 包中的 varImpPlot 生成的绘图的 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 限制(也许是为了一致性),我该如何解决这个问题跨地 block )?

最佳答案

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

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

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

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

dotchart of variable importance with manual x axis

关于r - 如何设置 varImpPlot 的 x 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765528/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com