collapsed nodes as triangles

1,391 views
Skip to first unread message

Will Chase

unread,
Sep 5, 2017, 3:57:09 PM9/5/17
to ggtree
Hi, I've looked all over google and the vingettes, but I can't seem to find a way to show collapsed nodes as triangles. 

I often want to collapse a subtree that is not of interest, but show it as a triangle to indicate that the collapsed node contains many taxa. 

See attached PDF where I've used TreeGraph2 to collapse Animals and Plants in this tree of life. Is there any way to replicate this look in ggtree?

Thanks!


eukaryotes_class.nwk5.pdf

bena...@gmail.com

unread,
Sep 7, 2017, 5:32:36 PM9/7/17
to ggtree
A rightward facing triangle is available as a UTF-8 character, 9668.

To using the collapse manipulator from collapse clade, you can then annotate the tip with the triangle as a geom_text2. You will need to change the hjust and vjust to adjust position and the cex to make it the right size. For example, if you wanted to collapse node 232 from the example bird.families dateset from ape:


library(ggtree)
library
(ape)
data
(bird.families)
coll
<- ggtree(bird.families) + geom_tiplab(cex=1.2) + xlim(0,70) + ylim(0,130)
coll
<- coll %>% collapse(node=232)
coll
<- coll + geom_text2(aes(subset=(node == 232)), cex=2, label=intToUtf8(9668), hjust =.2,vjust=.45)
coll
<- coll + geom_text2(aes(subset=(node == 232)), cex=1.5, vjust=0.2, label="Group",hjust = -.5)
coll



The collapse() manipulator also shortens the tree, which makes it impossible to represent how many taxa are included in the group. There would also be a way to collapse while preserving shape by grouping with OTUs, but that would get really complicated quite quickly. Easier to just do it manually if you have many collapsed nodes.


If you any other questions, don't forget to include some reproducible code by using the rtree() function, or the bird.families dataset.

Will Chase

unread,
Sep 13, 2017, 10:53:00 AM9/13/17
to ggtree
Thanks for the solution!

Yu, Guangchuang

unread,
Sep 13, 2017, 12:23:17 PM9/13/17
to Will Chase, ggtree
The triangle cannot be displayed properly on my Mac.

I load my emojifont package and use the Emoji font, and it works.




--
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/6005048d-d5ff-4f11-957b-e763287e46e2%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
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages