Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the node number #586

Open
Ruiqi-CUB opened this issue Sep 5, 2023 · 1 comment
Open

How to get the node number #586

Ruiqi-CUB opened this issue Sep 5, 2023 · 1 comment

Comments

@Ruiqi-CUB
Copy link

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

@brj1
Copy link
Contributor

brj1 commented Sep 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants