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?
The
plot()
output forglmtree
objects (and also otherpartykit
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 isnode_bivplot()
which has a number of arguments that can be tweaked. See?node_bivplot
for details. The relevant option here isylines
that you can increase to2
, for example.To pass arguments to the terminal panel function
tp_args
can be used: