Help with ggtree tip labeling in R
1
1
Entering edit mode
7.2 years ago
tpaisie ▴ 80

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 • 12k views
ADD COMMENT
3
Entering edit mode

Have a look the examples available here

ADD REPLY
3
Entering edit mode
7.2 years ago
Joseph Hughes ★ 3.0k

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")
ADD COMMENT

Login before adding your answer.

Traffic: 2526 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6