parttree | R Documentation |
Extracts the terminal leaf nodes of a decision tree with one or two numeric predictor variables. These leaf nodes are then converted into a data frame, where each row represents a partition (or leaf or terminal node) that can easily be plotted in coordinate space.
parttree(tree, keep_as_dt = FALSE, flipaxes = FALSE)
tree |
A tree object. Supported classes include
rpart::rpart.object, or the compatible classes from
from the |
keep_as_dt |
Logical. The function relies on |
flipaxes |
Logical. The function will automatically set the y-axis
variable as the first split variable in the tree provided unless
the user specifies |
This function can be used with a regression or classification tree containing one or (at most) two numeric predictors.
A data frame comprising seven columns: the leaf node, its path, a set
of coordinates understandable to ggplot2
(i.e., xmin, xmax, ymin, ymax),
and a final column corresponding to the predicted value for that leaf.
geom_parttree()
, rpart::rpart()
, partykit::ctree()
.
## rpart trees library("rpart") rp = rpart(Species ~ Petal.Length + Petal.Width, data = iris) parttree(rp) ## conditional inference trees library("partykit") ct = ctree(Species ~ Petal.Length + Petal.Width, data = iris) parttree(ct) ## rpart via partykit rp2 = as.party(rp) parttree(rp2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.