1

I want to label a specific branch (e.g., "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)

enter image description here

trilisser
  • 170
  • 8
  • 1
    Please include [minimal & reproducible code](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Have you had a look at the `ggtree` book, specifically the examples in [chapter 4](https://guangchuangyu.github.io/ggtree-book/chapter-ggtree.html)? Can you show what you've tried so far? – Maurits Evers Mar 17 '22 at 06:04
  • I think the code doesn't matter since it can be done with any tree. I've read the chapter but that way includes nexus editing and all branches instead specific ones. – trilisser Mar 17 '22 at 06:11
  • 2
    Then include any tree you like in your question. Also include exactly the values you would like in labels. It's much easier to show you how the code works with a specific example rather than making us do the work of coming up with one on our own which may or may not actually match up to your specific needs. – MrFlick Mar 17 '22 at 06:20
  • Ok, I understood. The code has been added. The label is "Group 1". – trilisser Mar 17 '22 at 06:29

1 Answers1

2

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()

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87