简体   繁体   中英

ggtree: how to label tree branches in the simplest way

I want to label a specific branch (eg, "Group 1") on the tree, but I didn't found a specific function to do that. Any ideas?

set.seed(123)
tree <- rtree(30)
plot(tree)

在此处输入图像描述

You're not actually using ggtree to plot here. If you wish to draw your tree with ggtree you could do something like this:

library(ggtree)
library(ggplot2)

set.seed(123)
tree <- rtree(30)

ggplot(tree) + 
  geom_tree() +
  geom_tiplab() +
  geom_text(aes(0.5, 20), label = 'Group 1', 
            check_overlap = TRUE, color = 'red', size = 6) +
  theme_void()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM