partykit - How to plot a glmtree without overlapping of terminal nodes?

我是研究僧i 提交于 2021-02-10 14:41:54

问题


I would like to plot a tree resulting from glmtree (partykit package). Unfortunately, the terminal nodes are overlapping and the labels of the graphs are no longer displayed properly.

The code that generates the tree is this one:

library(partykit)
library(aVirtualTwins)

data(sepsis)
attach(sepsis)

data <- cbind(y = survival, trt = as.factor(THERAPY), sepsis[,3:13])
formula <- as.formula(paste("y ~ trt", paste(names(sepsis[,3:13]), 
                            collapse = " + "), sep = " | "))
fit <- glmtree(formula, data, family = binomial)

plot(fit)

detach(sepsis)

Is there a way to customize the output of plot() in order to avoid overlapping of the terminal nodes?

Here is a picture of what I mean:


回答1:


The plot() output for glmtree objects (and also other partykit objects) is customizable through panel functions for all aspects of the tree (inner nodes, terminal nodes, edges, ...). The panel function employed by default for this kind of tree is node_bivplot() which has a number of arguments that can be tweaked. See ?node_bivplot for details. The relevant option here is ylines that you can increase to 2, for example.

To pass arguments to the terminal panel functiontp_args can be used:

plot(fit, tp_args = list(ylines = 2))



来源:https://stackoverflow.com/questions/53227676/partykit-how-to-plot-a-glmtree-without-overlapping-of-terminal-nodes

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