pruneTree {TreeSummarizedExperiment} | R Documentation |
pruneTree
is to remove branches that the specified leaves are in from
a phylo
tree
pruneTree(tree, rmLeaf, mergeSingle = TRUE)
tree |
A phylo object. |
rmLeaf |
A numeric or character vector. The labels or numbers of leaves to be removed. |
mergeSingle |
A logical value, TRUE or FALSE. If TRUE, the internal node
that has only one child will be omitted. For example, a tree has structure
as A-[B,C-D] (A has two children B, and C. C has a child D). If
|
A phylo object.
library(ggtree) data(tinyTree) ggtree(tinyTree, branch.length = "none") + geom_text2(aes(label = label), color = "darkorange", hjust = -0.1, vjust = -0.7) + geom_text2(aes(label = node), color = "darkblue", hjust = -0.5, vjust = 0.7) + geom_hilight(node = 18) + geom_point2() # remove the blue branch NT1 <- pruneTree(tree = tinyTree, rmLeaf = c(4, 5), mergeSingle = FALSE) ggtree(NT1, branch.length = "none") + geom_text2(aes(label = label), color = "darkorange", hjust = -0.1, vjust = -0.7) + geom_point2() # if mergeSingle = TRUE, the node (Node_17) is removed. NT2 <- pruneTree(tree = tinyTree, rmLeaf = c(4, 5), mergeSingle = TRUE) # or use the ape::drop.tip # NT3 <- ape::drop.tip(phy = tinyTree, tip = 4:5) # all.equal(NT2, NT3) ggtree(NT2, branch.length = "none") + geom_text2(aes(label = label), color = "darkorange", hjust = -0.1, vjust = -0.7) + geom_point2()