3

在因子变量上绘制树拆分会产生一个图,其中节点用因子的索引而不是级别的文本标记。如何绘制一棵树,其中标签是因子变量的实际水平?

例如,这里是足球运动员的样本数据。这个想法是国家(通过目标变量)解释了玩家的收入。国家被用作因子变量。

goals <- rpois(n = 5,lambda = 2)
income <- rnorm(100, goals*100000, sd = 1+goals*1000)
country <- rep(c("England","USA", "Nigeria", "Argentia", "Belgium"),
               times = 20)
player_df <- data.frame(income = income, country = country)

t1 <- rpart(income ~ ., 
      data = player_df, 
      cp = 0.01)

plot(t1); text(t1,)

这是结果:

在此处输入图像描述

4

1 回答 1

3

试试text(t1, pretty=FALSE)。这将防止因子标签被缩短。

于 2015-03-13T23:23:18.560 回答