Learn R Programming

dendextend (version 0.14.2)

intersect_trees: Intersect trees

Description

Return two trees after pruning them so that the only leaves left are the intersection of their labels.

Usage

intersect_trees(x1, x2, warn = FALSE, ...)

Arguments

x1
tree object (dendrogram/hclust/phylo)
x2
tree object (dendrogram/hclust/phylo)
warn
logical (FALSE). Should a warning be issued if there was a need to perform intersaction.
...
passed on

Value

  • A list with two pruned trees

See Also

prune, intersect, labels

Examples

Run this code
hc <- hclust(dist(USArrests[1:5,]), "ave")
dend <- as.dendrogram(hc)
labels(dend) <- 1:5
dend1 <- prune(dend, 1)
dend2 <- prune(dend, 5)
intersect_dend <- intersect_trees(dend1, dend2)

layout(matrix(c(1,1,2,3,4,5), 3,2, byrow=TRUE))
plot(dend, main = "Original tree")
plot(dend1, main = "Tree 1:\n original with label 1 pruned");
   plot(dend2, main = "Tree 2:\n original with label 2 pruned")
plot(intersect_dend[[1]],
      main = "Tree 1 pruned
      with the labels that intersected with those of Tree 2")
   plot(intersect_dend[[2]],
      main = "Tree 2 pruned
      with the labels that intersected with those of Tree 1")

Run the code above in your browser using DataLab