Learn R Programming

TreeSearch (version 0.3.2)

CollapseNode: Collapse nodes on a phylogenetic tree

Description

Collapses specified nodes or edges on a phylogenetic tree, resulting in polytomies.

Usage

CollapseNode(tree, nodes)

CollapseEdge(tree, edges)

Arguments

tree

A tree of class phylo.

nodes, edges

Integer vector specifying the nodes or edges in the tree to be dropped. (Use nodelabels or edgelabels to view numbers on a plotted tree.)

Value

tree, with the specified nodes or edges collapsed. The length of each dropped edge will (naively) be added to each descendant edge.

Examples

Run this code
# NOT RUN {
  library(ape)
  set.seed(1)
  
  tree <- rtree(7)
  par(mfrow=c(2, 1), mar=rep(0.5, 4))
  plot(tree)
  nodelabels()
  edgelabels(round(tree$edge.length, 2), cex=0.6, frame='n', adj=c(1, -1))
  
  newTree <- CollapseNode(tree, c(12, 13))
  plot(newTree)
  nodelabels()
  edgelabels(round(newTree$edge.length, 2), cex=0.6, frame='n', adj=c(1, -1))

# }

Run the code above in your browser using DataLab