File: dendro_data.tree.Rd

package info (click to toggle)
r-cran-ggdendro 0.1.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 368 kB
  • sloc: sh: 13; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 2,259 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dendro_tree.R
\name{dendro_data.tree}
\alias{dendro_data.tree}
\title{Extract data from regression tree object for plotting using ggplot.}
\usage{
\method{dendro_data}{tree}(model, type = c("proportional", "uniform"), ...)
}
\arguments{
\item{model}{object of class "tree", e.g. the output of tree()}

\item{type}{Either \code{proportional} or \code{uniform}. If this partially matches
"uniform", the branches are of uniform length. Otherwise they are
proportional to the decrease in impurity.}

\item{...}{ignored}
}
\value{
A list of three data frames:
\item{segments}{a data frame containing the line segment data}
\item{labels}{a data frame containing the label text data}
\item{leaf_labels}{a data frame containing the leaf label text data}
}
\description{
Extracts data to plot line segments and labels from a \code{tree::tree()} object.
This data can then be manipulated or plotted, e.g. using \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}.
}
\examples{
### Demonstrate tree

if (require(tree)) {
  require(ggplot2)
  require(MASS)
  data(cpus, package = "MASS")
  cpus.ltr <- tree(log10(perf) ~ syct + mmin + mmax + cach + chmin + chmax, 
                   data = cpus)
  tree_data <- dendro_data(cpus.ltr)
  ggplot(segment(tree_data)) +
    geom_segment(aes(x = x, y = y, xend = xend, yend = yend, size = n),
      colour = "lightblue"
    ) +
    scale_size("n") +
    geom_text(
      data = label(tree_data),
      aes(x = x, y = y, label = label), vjust = -0.5, size = 4
    ) +
    geom_text(
      data = leaf_label(tree_data),
      aes(x = x, y = y, label = label), vjust = 0.5, size = 3
    ) +
    theme_dendro()
}
}
\seealso{
\code{\link[=ggdendrogram]{ggdendrogram()}}

Other dendro_data methods: 
\code{\link{dendro_data.rpart}()},
\code{\link{dendro_data}()},
\code{\link{dendrogram_data}()},
\code{\link{rpart_labels}()}

Other tree functions: 
\code{\link{get_data_tree_leaf_labels}()},
\code{\link{tree_labels}()},
\code{\link{tree_segments}()}
}
\author{
Andrie de Vries, using code modified from original by Brian Ripley
}
\concept{dendro_data methods}
\concept{tree functions}