Learn R Programming

ggdendro (version 0.1-12)

dendro_data.tree: Extract data from regression tree object for plotting using ggplot.

Description

Extracts data to plot line segments and labels from a tree object. This data can then be manipulated or plotted, e.g. using ggplot.

Usage

## S3 method for class 'tree':
dendro_data(model, ...)

Arguments

model
object of class "tree", e.g. the output of tree()
...
ignored

Value

  • A list of three data frames:
  • segmentsa data frame containing the line segment data
  • labelsa data frame containing the label text data
  • leaf_labelsa data frame containing the leaf label text data

See Also

ggdendrogram Other dendro_data methods: dendro_data.dendrogram, dendrogram_data Other tree functions: get_data_tree_leaf_labels, tree_labels, tree_segments

Examples

Run this code
require(tree)
require(ggplot2)
require(MASS)
data(cpus, package="MASS")
cpus.ltr <- tree(log10(perf) ~ syct+mmin+mmax+cach+chmin+chmax, 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="blue", alpha=0.5) +
	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()

Run the code above in your browser using DataLab