This is a front end to
with the most useful arguments of that function.
rpart.plot(x=stop("no 'x' arg"), type=0, extra=0, under=FALSE, clip.right.labs=TRUE, fallen.leaves=FALSE, branch=if(fallen.leaves) 1 else .2, uniform=TRUE, digits=2, varlen=-8, faclen=3, cex=NULL, tweak=1, compress=TRUE, ycompress=uniform, snip=FALSE, ...)
rpartobject. The only required argument.
- Type of plot. Five possibilities:
0The default. Draw a split label at each split and a node label at each leaf.
1Label all nodes, not just leaves. Similar to
- Display extra information at the nodes. Possible values:
0No extra information (the default).
1Display the number of observations that fall in the node (per class for
- Applies only if
extra > 0. Default
FALSE, meaning put the extra text in the box. Use
TRUEto put the text under the box.
- Default is
TRUEmeaning ``clip'' the right-hand split labels, i.e. do not print
variable=. Applies only if
TRUE, display the leaves at the bottom of the graph.
- Controls the shape of the branch lines.
Specify a value between
0(V shaped branches) and
1(square shouldered branches). Default is
if(fallen.leaves) 1 else .2.
TRUE(the default), the vertical spacing of the nodes is uniform. If
FALSE, the nodes are spaced proportionally to the fit (more precisely, to the difference between a node's deviance and the sum of its two children's
- The number of significant digits in displayed numbers.
getOption("digits"). Details: Numbers from
- Length of variable names in text at the splits
(and, for class responses, the class in the node label).
-8, meaning truncate to eight characters. Possible values: =0 use full names. >0 call
- Length of factor level names in splits.
abbreviateto three characters. Possible values are as
varlenabove, except that
NULL, meaning calculate the text size automatically.
- Adjust the (possibly automatically calculated)
1, meaning no adjustment. Use say
tweak=1.2to make the text 20% larger. Note that font sizes are discrete, so the
cexyou ask f
TRUE(the default), make more space by shifting nodes horizontally where space is available. This often allows larger text. (This is the same as
plot.rpart's argument of the same name, except that here the
TRUE(the default unless
uniform=FALSE), make more space by shifting labels vertically where space is available. Actually, this only kicks in if the initial automatically calculated
cexis less than
TRUEto interactively trim the tree with the mouse. See
../doc/prp.pdf(or just try it).
- Extra arguments passed to
prpand the plotting routines. Any of
prp's arguments can be used.
- The returned value is identical to that of
data(ptitanic) tree <- rpart(survived ~ ., data=ptitanic, cp=.02) # cp=.02 because want small tree for demo old.par <- par(mfrow=c(2,2)) # put 4 figures on one page rpart.plot(tree, main="default rpart.plot (type = 0, extra = 0)") prp(tree, main="type = 4, extra = 6", type=4, extra=6, faclen=0) # faclen=0 to print full factor names rpart.plot(tree, main="extra = 106, under = TRUE", extra=106, under=TRUE, faclen=0) # the old way for comparison plot(tree, uniform=TRUE, compress=TRUE, branch=.2) text(tree, use.n=TRUE, cex=.6, xpd=NA) # cex is a guess, depends on your window size title("rpart.plot for comparison", cex=.6) par(old.par)