Node numbers can be seen using:
plotTree(tree,node.numbers=T)
## OR
plot(tree)
nodelabels() # i.e., no arguments
## OR
plot(tree)
nodelabels() # i.e., no arguments
If you want to bind a new tip or subtree to a terminal edge (i.e., an edge ending with a tip), then the 'node number' is just the index of the species in tree$tip.label. We can get this by (for tip name tip) setting where=which(tree$tip.label==tip). Alternatively, if we want to see the node & tip numbers plotted on the tree we could do:
> tree<-pbtree(n=20)
> plot(tree,no.margin=T,label.offset=0.1) # offset may vary
> nodelabels()
> tiplabels()
If adding multiple tips to the tree, remember to keep in mind that each time a new tip is added, the set of node numbers will change. For example:> plot(tree,no.margin=T,label.offset=0.1) # offset may vary
> nodelabels()
> tiplabels()
> tree2<-bind.tip(tree,"t21",where=23,position= 0.5*tree$edge.length[which(tree$edge[,2]==23)])
> ## this just added a new tip halfway along the edge
> ## ending at node 23
> plot(tree2,no.margin=T,label.offset=0.1)
> nodelabels()
> tiplabels()
> ## this just added a new tip halfway along the edge
> ## ending at node 23
> plot(tree2,no.margin=T,label.offset=0.1)
> nodelabels()
> tiplabels()
That's all for now!
Of course, I should have mentioned that to get a node number from the node label we should do:
ReplyDeletewhich(node==tree$node.label)
- Liam
Hi Liam, thanks for this post! I'm wondering how you can bind a new tip to an edge, rather than a node or tip. For example, I want to bind a new species "X" to the tree. The species is related to t8 and t7, but t8 and t7 are more closely related to each other than X. How would you go about this? My understanding is that bind.tip(newtree, tip.label="X", where=41) would result in a polytomy, but using the tip number references "20" or "19" would not result in the phylogeny I require as I want X as the outgroup. Thanks for your help!
ReplyDeleteDear Hester. bind.tip has an additional argument, position, which allows you to attach the tip along an edge rather than at a node. See the documentation page for the function & let us know if it provides sufficient guidance. -- Liam
DeleteHi Liam, thank you for your reply. What about the case the tip needs binding beyond the root? I.e. where bind.tip creates a trichotomy at the root. I find the documentation mentions this but I cannot find a solution to create an outgroup beyond the root.
ReplyDeleteI just posted an answer here: http://blog.phytools.org/2024/01/how-to-add-tip-below-root-node-using.html.
ReplyDeleteHi Liam, thank you all your work!
ReplyDeleteI would like to know if it is possible to bind several tips at once with bind.tip()? If yes, could you provide an example?
Thank you!
A