rpart plot text shorter

倾然丶 夕夏残阳落幕 提交于 2019-12-05 09:29:32

Here's an example that wraps long split labels over multiple lines. The maximum length of each line is 25 characters. Change the 25 to suit your purposes. (This example is derived from Section 6.1 in the rpart.plot vignette.)

tree <- rpart(Price/1000 ~ Mileage + Type + Country, cu.summary)

split.fun <- function(x, labs, digits, varlen, faclen)
{
    # replace commas with spaces (needed for strwrap)
    labs <- gsub(",", " ", labs)
    for(i in 1:length(labs)) {
        # split labs[i] into multiple lines
        labs[i] <- paste(strwrap(labs[i], width=25), collapse="\n")
    }
    labs
}

prp(tree, split.fun=split.fun)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!