This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Help with ggtree tip labeling in R

So I have a nexus tree file with the tips labeled by country. What I would like to do is label the tips of the tree with points color coded by country, like this:

Example photo of what I would like

So this data is in a different class than mine so the code for it won't work. So far I've been using ggtree and geom_tippoint in R to plot my tree and put dots at the tips of the tree, but i can't figure out how to color code them by country. Any help would be great!

phylogenetics r ggtree ggplot2

Have a look the examples available here

1 answer

Something like this should work:

tree <- read.tree(text = "(((A,B),(C,D)),E);")
p <- ggtree(tree)

You need to create a data frame that contains the taxa name and the country:

dd <- data.frame(taxa  = LETTERS[1:5], country = c(rep("FRA", 2), rep("UK", 2), rep("USA", 1)))
row.names(dd) <- NULL
print(dd)

Then you associate the data frame with you ggtree object

p <- p %<+% dd + geom_tippoint(aes(color=country))
p+theme(legend.position="right")

Log in to answer this question.