| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/dendro_tree.R |
| 3 |
\name{dendro_data.tree} |
| 4 |
\alias{dendro_data.tree} |
| 5 |
\title{Extract data from regression tree object for plotting using ggplot.} |
| 6 |
\usage{ |
| 7 |
\method{dendro_data}{tree}(model, type = c("proportional", "uniform"), ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{model}{object of class "tree", e.g. the output of tree()} |
| 11 |
|
| 12 |
\item{type}{Either \code{proportional} or \code{uniform}. If this partially matches |
| 13 |
"uniform", the branches are of uniform length. Otherwise they are |
| 14 |
proportional to the decrease in impurity.} |
| 15 |
|
| 16 |
\item{...}{ignored} |
| 17 |
} |
| 18 |
\value{ |
| 19 |
A list of three data frames: |
| 20 |
\item{segments}{a data frame containing the line segment data} |
| 21 |
\item{labels}{a data frame containing the label text data} |
| 22 |
\item{leaf_labels}{a data frame containing the leaf label text data} |
| 23 |
} |
| 24 |
\description{ |
| 25 |
Extracts data to plot line segments and labels from a \code{tree::tree()} object. |
| 26 |
This data can then be manipulated or plotted, e.g. using \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}. |
| 27 |
} |
| 28 |
\examples{ |
| 29 |
### Demonstrate tree |
| 30 |
|
| 31 |
if (require(tree)) { |
| 32 |
require(ggplot2) |
| 33 |
require(MASS) |
| 34 |
data(cpus, package = "MASS") |
| 35 |
cpus.ltr <- tree(log10(perf) ~ syct + mmin + mmax + cach + chmin + chmax, |
| 36 |
data = cpus) |
| 37 |
tree_data <- dendro_data(cpus.ltr) |
| 38 |
ggplot(segment(tree_data)) + |
| 39 |
geom_segment(aes(x = x, y = y, xend = xend, yend = yend, linewidth = n), |
| 40 |
colour = "lightblue" |
| 41 |
) + |
| 42 |
scale_size("n") + |
| 43 |
geom_text( |
| 44 |
data = label(tree_data), |
| 45 |
aes(x = x, y = y, label = label), vjust = -0.5, size = 4 |
| 46 |
) + |
| 47 |
geom_text( |
| 48 |
data = leaf_label(tree_data), |
| 49 |
aes(x = x, y = y, label = label), vjust = 0.5, size = 3 |
| 50 |
) + |
| 51 |
theme_dendro() |
| 52 |
} |
| 53 |
} |
| 54 |
\seealso{ |
| 55 |
\code{\link[=ggdendrogram]{ggdendrogram()}} |
| 56 |
|
| 57 |
Other dendro_data methods: |
| 58 |
\code{\link{dendro_data}()}, |
| 59 |
\code{\link{dendro_data.rpart}()}, |
| 60 |
\code{\link{dendrogram_data}()}, |
| 61 |
\code{\link{rpart_labels}()} |
| 62 |
|
| 63 |
Other tree functions: |
| 64 |
\code{\link{get_data_tree_leaf_labels}()}, |
| 65 |
\code{\link{tree_labels}()}, |
| 66 |
\code{\link{tree_segments}()} |
| 67 |
} |
| 68 |
\author{ |
| 69 |
Andrie de Vries, using code modified from original by Brian Ripley |
| 70 |
} |
| 71 |
\concept{dendro_data methods} |
| 72 |
\concept{tree functions} |