YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
839 stars 172 forks source link

use graph layout to visualize tree #460

Open GuangchuangYu opened 2 years ago

GuangchuangYu commented 2 years ago

pseudo-code:

ggtree <- function(..., layout = "xxx", ...) {
...
 if {layout not defined in ggtree} {
       p <- ggplot(..., layout = 'equal_angle')
       convert tree to igraph object
       apply layout to the object and extract node coordination
      replace p$data$x and p$data$y with new coordination
}

....

}

In this way, we can mostly keep the ggtree package unchanged, while supporting graph layouts.

see also https://github.com/YuLab-SMU/ggtree/commit/3ee8a38073e769045d50e441967846ed1fafb869.

xiangpin commented 2 years ago

I have implemented the primary feature

> library(MicrobiotaProcess)

Attaching package: ‘MicrobiotaProcess’

The following object is masked from ‘package:stats’:

    filter

> library(ggtree)
ggtree v3.3.0.901  For help: https://yulab-smu.top/treedata-book/

If you use ggtree in published research, please cite the most appropriate paper(s):

1. Guangchuang Yu. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96
2. Guangchuang Yu, Tommy Tsan-Yuk Lam, Huachen Zhu, Yi Guan. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution. 2018, 35(12):3041-3043. doi:10.1093/molbev/msy194
3. Guangchuang Yu, David Smith, Huachen Zhu, Yi Guan, Tommy Tsan-Yuk 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

> data(kostic2012crc)
> kostic2012crc %>% mp_filter_taxa(min.abun=1, min.prop=0.05) %>% mp_decostand(.abundance=Abundance, method="hellinger") %>% mp_cal_dist(.abundance=hellinger, cal.feature.dist=T) %>% hclust() %>% ggtree(layout=igraph::layout_with_kk) -> p3
> kostic2012crc %>% mp_filter_taxa(min.abun=1, min.prop=.05) %>% mp_extract_taxonomy() -> taxa.tab
> p3 %<+% taxa.tab + geom_tippoint(aes(color=Phylum), size=5)

xx3

> kostic2012crc %>% mp_filter_taxa(min.abun=1, min.prop=0.05) %>% mp_decostand(.abundance=Abundance, method="hellinger") %>% mp_cal_dist(.abundance=hellinger, cal.feature.dist=T) %>% hclust() %>% ggtree(layout=graphlayouts::layout_with_stress) -> p2
> p2 %<+% taxa.tab + geom_tippoint(aes(color=Phylum), size=5)

xx2

> kostic2012crc %>% mp_filter_taxa(min.abun=1, min.prop=0.05) %>% mp_decostand(.abundance=Abundance, method="hellinger") %>% mp_cal_dist(.abundance=hellinger, cal.feature.dist=T) %>% hclust() %>% ggtree(layout=igraph::layout_with_gem) -> p
> p %<+% taxa.tab + geom_tippoint(aes(color=Phylum), size=5)

xx

I found the RedeR might not export the coordinate of nodes.

xiangpin commented 2 years ago

3ee8a38

GuangchuangYu commented 2 years ago

looks good.