| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/dendro_rpart.R |
| 3 |
\name{dendro_data.rpart} |
| 4 |
\alias{dendro_data.rpart} |
| 5 |
\title{Extract data from classification tree object for plotting using ggplot.} |
| 6 |
\usage{ |
| 7 |
\method{dendro_data}{rpart}( |
| 8 |
model, |
| 9 |
uniform = FALSE, |
| 10 |
branch = 1, |
| 11 |
compress = FALSE, |
| 12 |
nspace, |
| 13 |
minbranch = 0.3, |
| 14 |
... |
| 15 |
) |
| 16 |
} |
| 17 |
\arguments{ |
| 18 |
\item{model}{object of class "tree", e.g. the output of tree()} |
| 19 |
|
| 20 |
\item{uniform}{if TRUE, uniform vertical spacing of the nodes is used; this |
| 21 |
may be less cluttered when fitting a large plot onto a page. The default is |
| 22 |
to use a non-uniform spacing proportional to the error in the fit.} |
| 23 |
|
| 24 |
\item{branch}{controls the shape of the branches from parent to child node. |
| 25 |
Any number from 0 to 1 is allowed. A value of 1 gives square shouldered |
| 26 |
branches, a value of 0 give V shaped branches, with other values being |
| 27 |
intermediate.} |
| 28 |
|
| 29 |
\item{compress}{if FALSE, the leaf nodes will be at the horizontal plot |
| 30 |
coordinates of 1:nleaves. If TRUE, the routine attempts a more compact |
| 31 |
arrangement of the tree. The compaction algorithm assumes uniform=TRUE; |
| 32 |
surprisingly, the result is usually an improvement even when that is not |
| 33 |
the case.} |
| 34 |
|
| 35 |
\item{nspace}{the amount of extra space between a node with children and a |
| 36 |
leaf, as compared to the minimal space between leaves. Applies to |
| 37 |
compressed trees only. The default is the value of branch.} |
| 38 |
|
| 39 |
\item{minbranch}{set the minimum length for a branch to minbranch times the |
| 40 |
average branch length. This parameter is ignored if uniform=TRUE. Sometimes |
| 41 |
a split will give very little improvement, or even (in the classification |
| 42 |
case) no improvement at all. A tree with branch lengths strictly |
| 43 |
proportional to improvement leaves no room to squeeze in node labels.} |
| 44 |
|
| 45 |
\item{...}{ignored} |
| 46 |
} |
| 47 |
\value{ |
| 48 |
A list of three data frames: |
| 49 |
\item{segments}{a data frame containing the line segment data} |
| 50 |
\item{labels}{a data frame containing the label text data} |
| 51 |
\item{leaf_labels}{a data frame containing the leaf label text data} |
| 52 |
} |
| 53 |
\description{ |
| 54 |
Extracts data to plot line segments and labels from a |
| 55 |
\code{\link[rpart:rpart]{rpart::rpart()}} classification tree object. This data can then be |
| 56 |
manipulated or plotted, e.g. using \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}. |
| 57 |
} |
| 58 |
\details{ |
| 59 |
This code is in essence a copy of \code{\link[rpart:plot.rpart]{rpart::plot.rpart()}}, retaining |
| 60 |
the plot data but without plotting to a plot device. |
| 61 |
} |
| 62 |
\examples{ |
| 63 |
### Demonstrate rpart |
| 64 |
|
| 65 |
if (require(rpart)) { |
| 66 |
require(ggplot2) |
| 67 |
fit <- rpart(Kyphosis ~ Age + Number + Start, method = "class", |
| 68 |
data = kyphosis) |
| 69 |
fitr <- dendro_data(fit) |
| 70 |
ggplot() + |
| 71 |
geom_segment(data = fitr$segments, |
| 72 |
aes(x = x, y = y, xend = xend, yend = yend) |
| 73 |
) + |
| 74 |
geom_text(data = fitr$labels, aes(x = x, y = y, label = label)) + |
| 75 |
geom_text(data = fitr$leaf_labels, aes(x = x, y = y, label = label)) + |
| 76 |
theme_dendro() |
| 77 |
} |
| 78 |
} |
| 79 |
\seealso{ |
| 80 |
\code{\link[=ggdendrogram]{ggdendrogram()}} |
| 81 |
|
| 82 |
Other dendro_data methods: |
| 83 |
\code{\link{dendro_data}()}, |
| 84 |
\code{\link{dendro_data.tree}()}, |
| 85 |
\code{\link{dendrogram_data}()}, |
| 86 |
\code{\link{rpart_labels}()} |
| 87 |
|
| 88 |
Other rpart functions: |
| 89 |
\code{\link{rpart_labels}()}, |
| 90 |
\code{\link{rpart_segments}()} |
| 91 |
} |
| 92 |
\concept{dendro_data methods} |
| 93 |
\concept{rpart functions} |