R:改变地块大小

R: Changing Plot Sizes

我正在使用 R 编程语言。我 运行 使用“rpart”库的决策树函数:

library(rpart)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)

从这里开始,我尝试绘制结果:

 plot(z.auto)

本returns以下剧情:

以及几条警告信息:

Warning messages:
1: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
2: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
3: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
4: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
5: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
6: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
7: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
8: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter
9: In doTryCatch(return(expr), name, parentenv, handler) :
  "use.n" is not a graphical parameter

我正在尝试为该图添加更多信息(例如变量名称和决策规则)。我做了一些研究,发现您可以为该图添加标签:

text(z.auto, use.n=TRUE)

本returns以下剧情:

这个情节更好 - 但文本被截断到底部。有没有一种直接的方法来更改绘图的内部大小,以便所有文本都不会被截断?

注意:我使用的计算机没有互联网连接或 USB 端口 - 它只有 R 和一些常用库(例如 ggplot2、rpart、party、partykit 等),我无法在我的电脑上安装“rpart.plot”库 (https://www.rdocumentation.org/packages/rpart.plot/versions/3.0.9),否则我会尝试使用这个库。

谢谢

使用xpd=TRUE。另外 cex= 可能有助于缩放字体大小。

plot(z.auto)
text(z.auto, use.n=TRUE, xpd=TRUE, cex=.8)

您可以使用 rattle 包来绘制 CART,例如

library(rpart)
library(rpart.plot)
library(rattle)

z.auto <- rpart(Mileage ~ Weight, car.test.frame)
#Plotting using `rpart.plot` package
prp(z.auto, type = 1)

#Plotting using `rattle` package
fancyRpartPlot(z.auto)