问题
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