I would recommend not tweaking this afterwards but keeping the variable names in sync. But for changing the labels used in the plots you only have to change names(party_object$data)
.
As a simple reproducible example consider the iris
data:
library("rpart")
library("partykit")
data("iris", package = "datasets")
names(iris)
## [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
Now we change the names in the data to something abbreviated:
names(iris) <- c("SL", "SW", "PL", "PW", "S")
And then grow the rpart()
tree and convert it to party
:
rp <- rpart(S ~ SL + SW + PL + PW, data = iris)
py <- as.party(rp)
plot(py)

Then we can simply relabel the variables in $data
(note that the order changed, the response is listed first) and plot again:
names(py$data)
## [1] "S" "SL" "SW" "PL" "PW"
names(py$data) <- c("species", "sepal_length", "sepal_width", "petal_length", "petal_width")
plot(py)

Most things should work completely fine with this tweaked party
object. However, the variable names in the formula
and the data
are now not in sync. This might lead to problems in some setting. But plotting should be fine.
library('rpart') library('partykit') library('party') tmp <- read.table('Example.csv',header=FALSE,sep=' ') names(tmp) <- c('U','X','AC','AD','AY') ###############Regression tree############## tree.model <- rpart(U ~ X + AC + AD + AY,data=na.omit(tmp)) plot(as.party(tree.model))
– Tobias Piechowiak