gpt4 book ai didi

r - R:绘制决策树标签会使文本被截断

转载 作者:行者123 更新时间:2023-12-03 12:10:51 24 4
gpt4 key购买 nike

(我仍在学习如何在R中处理图像;这是rpart package: Save Decision Tree to PNG的延续)

我正在尝试以PNG格式保存rpart的决策树图,而不是提供的后记。我的代码如下所示:

png("tree.png", width=1000, height=800, antialias="cleartype")
plot(fit, uniform=TRUE,
main="Classification Tree")
text(fit, use.n=TRUE, all=TRUE, cex=.8)
dev.off()

但会剪掉两侧边缘节点的一些标签。这在原始 post图像中不是问题,我已将其转换为png以进行检查。我尝试在 oma中同时使用 marpar设置,建议将其设置为解决标签/文本问题的方法,并且都在图像周围添加了空白,但不再显示标签。有什么办法可以使文本适合?

最佳答案

rpart.plot程序包绘制rpart树并自动处理
margin 及相关问题。使用rpart.plot(而不是plot包中的textrpart)。例如:

library(rpart.plot)
data(ptitanic)
fit <- rpart(survived~., data=ptitanic)
png("tree.png", width=1000, height=800, antialias="cleartype")
rpart.plot(fit, main="Classification Tree")
dev.off()

关于r - R:绘制决策树标签会使文本被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426007/

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