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 for the extra
and col.palette
arguments mean that this function automatically creates a colored plot
suitable for the type of model (whereas prp
by default
creates a minimal plot). In detail the different defaults are:
  rpart.plot    prp    
type    2    0   
extra    "auto"    0   
fallen.leaves    TRUE    FALSE   
varlen    0    8   
faclen    0    3   
box.palette    "auto"    0   
The function rpart.plot.version1
is compatible with
old versions of this function and has the same defaults as prp
.
1 2 3 4 5 6 7 8 
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 
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 probabilities times the fraction of observations in the node (the probability relative to all observations, sum across all leaves is 1). +100 Add Note 1: 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 
cex 
Default 
tweak 
Adjust the (possibly automatically calculated) 
snip 
Default 
box.palette 
Palette for coloring the node boxes based on the fitted value.
This is a vector of The special value box.palette=0 (default for The special value box.palette="auto" (default for
Otherwise specify a predefined palette
e.g. box.palette="Grays" for the predefined gray palette (a range of grays).
The predefined palettes are (see the 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.plot.version1
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  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,
box.palette="Grays", # override default GnBu palette
main="titanic survived\nbox.palette = \"Grays\"")
#
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.