Łukasz Deryło
Łukasz Deryło

Reputation: 1860

Change x-axis limits for partykit::lmtree (mob) plots

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)

To get this: enter image description here

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

Upvotes: 1

Views: 163

Answers (1)

Achim Zeileis
Achim Zeileis

Reputation: 17203

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))

mytree

Upvotes: 1

Related Questions