In the function rpart.plot (from the package rpart.plot, extension to the rpart package) there is the argument box.col
, which controls the colour of the nodes in the tree. How do I set it such that it colours the nodes so that nodes of the same response are coloured the same?
I've tried a number of different variants with the box.col
argument, such as using cols
as factors, which ignores the colours selected. The closest I have so far is shown below
set.seed(1);x <- runif(100)
set.seed(2);y <- runif(100)
data <- matrix(c(x,y),ncol=2)
fact <- as.numeric(factor(--((x > 0.5 & y < 0.5))))
fact[x < 0.1] = 3
cols <- (c("grey80", "red", "blue"))
plot(data, col=fact)
t1 <- rpart(factor(fact) ~ data)
rpart.plot(t1, type=5, extra=2,
box.col=cols)
I expect/want each matching response node to be coloured the same. In the given code, I would expect the '1' nodes to be grey80, the '2's to be red, and the '3' to be blue. The above plot shows what actually happens, which is not helpful.
As mentioned in the first part, how do I set it such that it colours the nodes so that nodes of the same response are coloured the same?