ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

How to get the node number

Open Ruiqi-CUB opened this issue 1 year ago • 1 comments

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

Ruiqi-CUB avatar Sep 05 '23 08:09 Ruiqi-CUB

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.

brj1 avatar Sep 06 '23 22:09 brj1