bind.tip: Attaches a new tip to a tree

View source: R/utilities.R

bind.tipR Documentation

Attaches a new tip to a tree

Description

Adds a new tip to the tree.

Usage

bind.tip(tree, tip.label, edge.length=NULL, where=NULL, position=0,
   interactive=FALSE, ...)

Arguments

tree

receptor tree.

tip.label

a string containing the species name for the new tip.

edge.length

edge length for the new tip (a scalar).

where

node number to attach new tip. If position>0 then then tip will be attached rootward of the specified node. Node numbers can also be tips, in which case the new tip will be added along the terminal edge. To find out the tip number for given species with name "species" type: which(tree$tip.label=="species").

position

distance rootward of the node to add the new tip.

interactive

logical value indicating whether or not the species should be added interactively. (Defaults to FALSE.)

...

arguments to be passed to plotTree (for interactive=TRUE.)

Details

If the tree is ultrametric and no branch length is specified, then edge.length is scaled so that the tree remains ultrametric after the new tip is added.

Wrapper function for ape bind.tree. Note that interactive=TRUE works only for right-facing phylograms.

Value

An object of class "phylo".

Author(s)

Liam Revell liam.revell@umb.edu

References

Revell, L. J. (2024) phytools 2.0: an updated R ecosystem for phylogenetic comparative methods (and other things). PeerJ, 12, e16505.

Examples

set.seed(123)
par(mfrow=c(3,1))
## generate tree
tree<-pbtree(b=0.1, n=10)
## plot original tree
plotTree(tree,mar=c(2.1,0.1,2.1,0.1))
axisPhylo()
mtext("a)",adj=0)
## add an extant tip ("t_extant") sister to taxon 't5'
## with divergence time of 4.5 Ma
node <- which(tree$tip.label=="t5")
tree <- bind.tip(tree, tip.label="t_extant",
  where=node, position=4.5)
# plot to see the result
plotTree(tree,mar=c(2.1,0.1,2.1,0.1))
axisPhylo()
mtext("b)",adj=0)
## add an extinct tip ("t_extinct") sister to 't2' with
## divergence time of 7.8 Ma and duration (edge length) of
## 3.3 Ma
node <- which(tree$tip.label=="t2")
tree <- bind.tip(tree, tip.label="t_extinct", where=node,
  position=7.8, edge.length=3.3)
## plot to see the result
plotTree(tree,mar=c(2.1,0.1,2.1,0.1))
axisPhylo()
mtext("c)",adj=0)
par(mar=c(5.1,4.1,4.1,2.1),mfrow=c(1,1))

phytools documentation built on June 22, 2024, 10:39 a.m.