How to create circular ggtree with multiple gheatmap annotations of continuous variable data?

1,817 views
Skip to first unread message

Shawn Higdon

unread,
Feb 13, 2019, 9:41:58 PM2/13/19
to ggtree
Hello,

I am in the process of using ggtree to visualize results from 5 different biochemical assays on about 500 microbial isolates.

The tree has been created, and I have the results from all five biochemical assays in a single dataframe.

The biochemical assay data for each isolate are numerical.

What I would like to do is have a single circular tree with a gheatmap that corresponds to results from each biochemical assay of the microbes arranged in outer rings, each with a different color scale.

I found a useful start to a solution here: https://github.com/GuangchuangYu/ggtree/issues/78

I attempted to adapt the code for my specific application, but ran into the issue of the color scale being replaced with each gheatmap implementation, where all gheatmaps are plotted with a single color scale - that being of the final layer. The Github issue linked above uses `scale_fill_manua()` to map discrete annotations in multiple rings, but I cant figure out how to adapt this approach for continuous data variables.

I'd like to know if there is a way to map specific color scales to each of the gheatmaps corresponding to a data from individual assays so that I can have several rings each with a different color scale.

The code I have so far is below:

```{r}

# Make tree
sm_k31_tree <- ggtree(sm_k31_phylo, color = "black", size = 0.3, layout = "fan", open.angle = 6)


# Add gheatmap 1 for biochemical assay 1
pgp1 <- gheatmap(sm_k31_tree, pgp_master[, "BNF", drop=F], width=0.1,
                 colnames_angle = 90, colnames_offset_x =0.4, font.size = 3,
                 color = "black") + scale_fill_gradient(high = "blue", low = "pink")


# Add gheatmap 2 for assay 2
pgp2 <- gheatmap(pgp1, pgp_master[, "ACC", drop=F], offset = 0.5, width = 0.1,
                 colnames_angle = 90, colnames_offset_x = 0.5, font.size = 3,
                 color = "black", high = "green", low = "red")


# create alternate for legend extract
pgp2x <- gheatmap(sm_k31_tree, pgp_master[, "ACC", drop=F], offset = 0.8, width = 0.1,
                 colnames_angle = 90, colnames_offset_x = 0.5, font.size = 2,
                 color = "black", high = "green", low = "red")


# extract legends
require(cowplot)
pgp_leg1 <- get_legend(pgp1)
pgp_leg2 <- get_legend(pgp2x)


# create plot object
pp <- pgp2 + theme(legend.position = "none") + geom_tiplab2(aes(angle=angle), size = 0.8, color = "black", offset = 2)


# plot object with legends
plot_grid(pp, pgp_leg1, pgp_leg2, ncol = 3, rel_widths = c(1, 0.1, 0.1))

```

Is my idea even possible? I imagine there is a way but that my limited knowledge of Rcolor packages is a problem. 

Any guidance, advice or help will be greatly appreciated!

Thanks!

Yu, Guangchuang

unread,
May 16, 2019, 3:09:27 AM5/16/19
to Shawn Higdon, ggtree

--
1. 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
2. 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. doi: 10.1093/molbev/msy194
3. Book: https://yulab-smu.github.io/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 post to this group, send email to bioc-...@googlegroups.com.
Visit this group at https://groups.google.com/group/bioc-ggtree.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/b85ddef6-f01a-4c71-bed0-5740e677c2da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu PhD
Professor
School of Basic Medical Sciences
Southern Medical University
Guangzhou, China
-~----------~----~----~----~------~----~------~--~---

Shawn Higdon

unread,
May 16, 2019, 5:28:15 PM5/16/19
to ggtree
Greetings Professor,

Thank you so much for responding to this  issue and for providing an elegant solution. I managed to follow the added example in your book chapter and have the multiple continuous variables plotted as rings around the tree.

However, I have now encountered the issue of gheatmap legends that lack titles when rendering the plot.

I attempted to follow the code in your example using the scale_fill_viridis_c() function like so:

```{r}

# Make tree
sm_k31_tree <- ggtree(sm_k31_phylo, color = "black", size = 0.3, layout = "fan", open.angle = 6)


# Add gheatmap 1 for biochemical assay 1
pgp1 <- gheatmap(sm_k31_tree, pgp_master[, "BNF", drop=F], width=0.1,
                 colnames_angle = 90, colnames_offset_x =0.4, font.size = 3) + 
  scale_fill_viridis_c(option="C", name = "BNF") 


# Add gheatmap 2 for assay 2
pgp2 <- pgp1 + new_scale_fill()

pgp_all <- gheatmap(pgp2, pgp_master[, "ACC", drop=F], offset = 0.5, width = 0.1,
                 colnames_angle = 90, colnames_offset_x = 0.5, font.size = 3) + 
  scale_fill_viridis_c(option = "A", name="ACC")
 
pgp_all

```

ggtree_circ_pgp.png



However, reading the documentation for the scale_fill_viridis_c() function I do not see and description for an argument to set the name as you have done in your example.

Am I missing something, or maybe one of my packages is out of date?

I am using:

R version 3.5.1
ggtree version 1.14.6
viridis version 0.5.1
ggnewscale version 0.2.0
ggplot2 version 3.1.1

Any guidance on how I might generate these legend titles or why they are not showing up in the plot will be greatly appreciated! Thank you so much.

To unsubscribe from this group and stop receiving emails from it, send an email to bioc-...@googlegroups.com.

Yu, Guangchuang

unread,
May 16, 2019, 10:29:43 PM5/16/19
to Shawn Higdon, ggtree

In current release of ggtree, the legend title is disable by default. You can use +theme(legend.title=element_text()) to enable it.

In furture version, legend title will be enable by default, and user can use gheatmap(..., legend_title="your title") to specify the title name, see https://github.com/GuangchuangYu/ggtree/commit/c00aac1c13b98fd115c367063d07ee157cb97691.

--
1. 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. doi: 10.1093/molbev/msy194
2. 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

3. Book: https://yulab-smu.github.io/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 post to this group, send email to bioc-...@googlegroups.com.
Visit this group at https://groups.google.com/group/bioc-ggtree.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages