iTOL style in gheatmap

756 views
Skip to first unread message

YiweiZhu

unread,
May 24, 2021, 9:56:40 PM5/24/21
to ggtree

Hi, Prof. Yu,
Is it possible to plot gheatmap in iTOL style? Specifically, the shape of each cell was a circle instead of a square, filling a certain color or leave it blank.
F3.large.jpg

xush...@gmail.com

unread,
May 27, 2021, 9:27:24 AM5/27/21
to ggtree
Yes, It can be generated easily with ggtreeExtra and ggtree. You can refer to the following codes

```
library(ggtree)                                                                                                                                                                                                    library(ggstar)
library(ggtreeExtra)
library(ggplot2)

set.seed(123)

n <- 100

tr <- rtree(n)

dat1 <- data.frame(
           id=rep(tr$tip.label, 8),
           sample=c(rep(c("A1","A2", "A3", "A4"), each=n),
                    rep(c("B1", "B2", "B3", "B4"), each=n)),
           group=c(rep("A", n * 4), rep("B", n * 4)),
           subgroup=rep("T", n*8)
       )

dat1[sample(nrow(dat1), 700), "subgroup"] <- NA
dat1$subgroup <- ifelse(!is.na(dat1$subgroup), dat1$group, NA)

gf1 <- geom_fruit(
           data=dat1,
           geom=geom_star,
           mapping=aes(x=sample, y=id, color=group),
           starshape=15,
           pwidth=0.12
           )

gf2 <- geom_fruit(
           data=dat1,
           geom=geom_star,
           mapping=aes(x=sample, y=id, fill=subgroup),
           starstroke=0,
           starshape = 15,
           pwidth=0.12,
           axis.params = list(axis="x", text.size=1.2, vjust=1, line.size=0)
       )

linecolor <- scale_color_manual(values=c("red", "blue"))
fillcolor <- scale_fill_manual(values=c("red", "blue"), na.translate = FALSE)

fg <- geom_fruit_list(gf2, gf1, linecolor, fillcolor)
p <- ggtree(tr)

p1 <- p + fg + scale_y_continuous(limits=c(-1, NA))
p1
```
test.png

YiweiZhu

unread,
May 27, 2021, 8:30:16 PM5/27/21
to ggtree
Great! Thank you very much, Shuangbin!

Yu, Guangchuang

unread,
May 28, 2021, 12:01:52 PM5/28/21
to YiweiZhu, ggtree
and to add background colors for tip labels is easy. try the following codes:

x = rtree(30)
d = data.frame(label=x$tip.label, group = sample(letters[1:3], 30, replace=T))
p <- ggtree(x) %<+% d
p + geom_tiplab(geom='label', aes(fill=group), label.size=0)

--
1. G Yu*. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. https://doi.org/10.1002/cpbi.96
2. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2020, 37(2):599-603. http://dx.doi.org/10.1093/molbev/msz240
3. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
4. 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. https://doi.org/10.1111/2041-210X.12628
5. Book: https://yulab-smu.top/treedata-book/
---
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/c37edf40-71bb-4a3f-8ccd-c8383c4c5161n%40googlegroups.com.


--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor, Associate director
Department of Bioinformatics
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---
Reply all
Reply to author
Forward
0 new messages