display only certain labels with geom_tiplab() or geom_tiplab2()

2,719 views
Skip to first unread message

Mordecai Guzmann

unread,
Oct 3, 2017, 10:17:43 PM10/3/17
to ggtree
Hello!

I am trying to make a circular tree with some reference sequences and I only want to add labels of the reference sequences.
How would you solve it?

Thank you, M

bena...@gmail.com

unread,
Oct 3, 2017, 10:37:32 PM10/3/17
to ggtree
Hi Mordecai,

There are a few options, the easiest one depends on your labels. You can subset explicitly inside geom_tiplab2, or use a matching expression if all the reference sequences have a common labeling scheme.

Can you post an example dataset?

Mordecai Guzmann

unread,
Oct 4, 2017, 1:10:30 AM10/4/17
to ggtree
Hello and thanks for the quick and nice reply!

I cannot show the data, but I can show how I get my tree. Firstly:

>tree <- read.tree("filename.tre")        
>tree_p <- ggtree(tree, layout="fan", branch.length="none", open.angle=10)
>tree$Nnode
[1] 1031
> tree$tip.label
[1] "S5-MP..."                     
[2] "S5-MP..."
[...]                     
[971] "REF..."     #This i want to label, but not the first lines!

So I get my round tree. Which I want to use with gheatmap() later on, to display information about the found species. However some of the tips I would like to label before plotting the heatmap:

 >tree_p + geom_tiplab()
*shows the tree with all labels attached*

Now I don`t know how to tell geom_tiplab2() to only put labels on certain tips. (like tip number 971) 

So, it is not such a complicated problem, but I haven`t found any good documentations on geom_tiplab2().

All the labels I want start with "REF" and all the ones I don`t need start with "S", so this is an easy way to discriminate.

Thank you for your help and have a nice day!
Mordecai

bena...@gmail.com

unread,
Oct 4, 2017, 7:23:11 PM10/4/17
to ggtree
Hello,

To produce a reproducible example, I use the ape package and the rcoal() function to make sample trees. The following example shows how you can use the aes() and the subset=() fucntions to plot tips based on node number, or instead based on a match in the name.  Hope this helps.

library(ape)
library
(ggtree)

tree
<- rcoal(5)
tree$tip
.label <- c("REF-1","REF-2","S1","S2","S3")
full_tree    
<- ggtree(tree) + xlim(0,2) + geom_tiplab()
full_tree
#Since we know the first two are reference, use the order
limited_tree1
<- ggtree(tree) + xlim(0,2) + geom_tiplab(aes(subset=(node %in% c(1,2))))
limited_tree1
#But we also know the names are different, so we can use that as well
#grepl() searches for 'RE' in the label, and returns true if found
#we use aes(subset=()) to only print those with the subset condition == TRUE
limited_tree2
<- ggtree(tree) + xlim(0,2) + geom_tiplab(aes(
      subset
=(grepl('RE',label,fixed=TRUE)==TRUE)))
limited_tree2

Mordecai Guzmann

unread,
Oct 4, 2017, 9:37:52 PM10/4/17
to ggtree
Hello Bena!

I played around with subset and grepl but I could not figure out how to solve it or use them together. Thank you for our advice! This helps me so much!

Thanks a lot!
M

Yu, Guangchuang

unread,
Oct 9, 2017, 1:46:26 AM10/9/17
to Mordecai Guzmann, ggtree

--
G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. doi:10.1111/2041-210X.12628
 
Homepage: https://guangchuangyu.github.io/ggtree
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/225debf1-bdcd-4829-bab5-4299193d7fea%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, Postdoc researcher
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---

Mordecai Guzmann

unread,
Oct 16, 2017, 1:52:50 AM10/16/17
to ggtree
Thank you!

This also helps, as further examples help me understand the syntax better!
I am glad  there are so many helpful poeple :D
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.

To post to this group, send email to bioc-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages