ggtree
ggtree copied to clipboard
How to get the node number
trafficstars
Hi Dr. Yu,
I am trying to annotate my tree in ggtree. Do you happen to know How I can get the node number? Is there a way to plot tree with tip/internal node numbers?
Thanks a lot
You can get them with geom_text, geom_nodelab, geom_tiplab, etc. by setting label = node in the aes. For example:
tree <- rtree(10)
ggtree(tree) + geom_text(aes(label = node), hjust = -0.5) # node number
ggtree(tree) + geom_nodelab(aes(label = node), hjust = -0.5) # just internal node number
ggtree(tree) + geom_tiplab(aes(label = node), hjust = -0.5) # just tip number
The hjust moves the labels over a bit so they can be more easily seen.