Just like in title: I'd like to change x-axis limits for partykit::lmtree
(mob
) plots.
Toy example
Let shape of Y~X+X^2
regression depend on A
:
A <- rep(1:5, each=4)
X <- 1:20
Y <- X*A+(A<3)*X^2+rnorm(20, mean=10)
Now build lmtree
with polynomial term and plot:
library(partykit)
mytree <- lmtree(Y~poly(X,2,raw=T) | A, minsize=3)
plot(mytree)
Limits of X-axis are clearly based on range of poly(X,2,raw=T)
not on range of X
. How can I change them?
What I have tried
tp_args=list(xlim=c(1,20))
. This failed because (I think) there is no xlim
parameter in node_bivplot()
that controls plots.node_bivplot()
that controls axes. I can't see any.Y~X+I(X^2)
inside lmtree
. This produces separate plots for X
and I(X^2)
on each leaf.Currently, the xscale
and yscale
arguments (grid graphics equivalents to the base graphics arguments xlim
and ylim
) are set internally in node_bivplot()
and cannot be modified through arguments.
In your case I would recommend to set up the two regressors from the polynomial manually (X + I(X^2)
) and then only create a terminal panel for the first of these two regressors (which = 1
):
mytree <- lmtree(Y ~ X + I(X^2) | A, minsize = 3)
plot(mytree, tp_args = list(which = 1))