Description Usage Arguments Value Author(s) See Also Examples
Plot an rpart
model, automatically tailoring the plot
for the model's response type.
For an overview, please see the package vignette Plotting rpart trees with the rpart.plot package.
This function is a simplified frontend to prp
,
with only the most useful arguments of that function, and
with different defaults for some of the arguments.
The different defaults mean that this function automatically creates a
colored plot suitable for the type of model (whereas prp
by default creates a minimal plot).
See the prp
help page for a table showing the
different defaults.
1 2 3 4 5 6 7 8 9 
To start off, look at the arguments x
, type
and extra
.
Just those arguments will suffice for many users.
If you don't want a colored plot, use box.palette=0
.
x 
An 
type 
Type of plot. Possible values: 0 Draw a split label at each split and a node label at each leaf. 1 Label all nodes, not just leaves.
Similar to 2 Default.
Like 3 Draw separate split labels for the left and right directions. 4 Like 5 Show the split variable name in the interior nodes. 
extra 
Display extra information at the nodes. Possible values: "auto" (case insensitive) Default. 0 No extra information. 1 Display the number of observations that fall in the node
(per class for 2 Class models: display the classification rate at the node,
expressed as the number of correct classifications and the number
of observations in the node. 3 Class models: misclassification rate at the node, expressed as the number of incorrect classifications and the number of observations in the node. 4 Class models: probability per class of observations in the node (conditioned on the node, sum across a node is 1). 5 Class models:
like 6 Class models: the probability of the second class only. Useful for binary responses. 7 Class models:
like 8 Class models: the probability of the fitted class. 9 Class models: The probability relative to all observations – the sum of these probabilities across all leaves is 1. This is in contrast to the options above, which give the probability relative to observations falling in the node – the sum of the probabilities across the node is 1. 10 Class models:
Like 11 Class models:
Like +100 Add Note: Unlike 
under 
Applies only if 
fallen.leaves 
Default 
digits 
The number of significant digits in displayed numbers.
Default 
varlen 
Length of variable names in text at the splits
(and, for class responses, the class in the node label).
Default 0 use full names (default). greater than 0 call less than 0 truncate variable names to the shortest length where they are still unique,
but never truncate to shorter than 
faclen 
Length of factor level names in splits.
Default 
roundint 
If 
cex 
Default 
tweak 
Adjust the (possibly automatically calculated) 
clip.facs 
Default 
clip.right.labs 
Applies only if 
snip 
Default 
box.palette 
Palette for coloring the node boxes based on the fitted value.
This is a vector of The special value The special value Otherwise specify a predefined palette
e.g. Prefix the palette name with 
shadow.col 
Color of the shadow under the boxes.
Default 
... 
Extra arguments passed to 
The returned value is identical to that of prp
.
Stephen Milborrow, borrowing heavily from the rpart
package by Terry M. Therneau and Beth Atkinson,
and the R port of that package by Brian Ripley.
The package vignette Plotting rpart trees with the rpart.plot package
prp
rpart.rules
Functions in the rpart
package:
plot.rpart
text.rpart
rpart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  old.par < par(mfrow=c(2,2)) # put 4 figures on one page
data(ptitanic)
#
binary.model < rpart(survived ~ ., data = ptitanic, cp = .02)
# cp = .02 for small demo tree
rpart.plot(binary.model,
main = "titanic survived\n(binary response)")
rpart.plot(binary.model, type = 3, clip.right.labs = FALSE,
branch = .4,
box.palette = "Grays", # override default GnBu palette
main = "type = 3, clip.right.labs = FALSE, ...\n")
#
anova.model < rpart(Mileage ~ ., data = cu.summary)
rpart.plot(anova.model,
shadow.col = "gray", # add shadows just for kicks
main = "miles per gallon\n(continuous response)\n")
#
multi.class.model < rpart(Reliability ~ ., data = cu.summary)
rpart.plot(multi.class.model,
main = "vehicle reliability\n(multi class response)")
par(old.par)

Loading required package: rpart
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.