r - rpart plot text shorter -
i using prp
function rpart.plot
package plot tree. categorical data states, gives long list of variables , makes less readable. there way wrap text 2 or more lines if exceeds length?
here's example wraps long split labels on multiple lines. maximum length of each line 25 characters. change 25 suit purposes. (this example derived section 5.1 in rpart.plot vignette.)
tree <- rpart(price/1000 ~ mileage + type + country, cu.summary) split.fun <- function(x, labs, digits, varlen, faclen) { # replace commas spaces (needed strwrap) labs <- gsub(",", " ", labs) for(i in 1:length(labs)) { # split labs[i] multiple lines labs[i] <- paste(strwrap(labs[i], width=25), collapse="\n") } labs } prp(tree, split.fun=split.fun)
Comments
Post a Comment