# knitr::opts_chunk$set(echo = TRUE, cache = TRUE)
knitr::opts_chunk$set(
   # cache = TRUE,
   dpi = 60,
  comment = '#>',
  tidy = FALSE)
library(heatmaply)
library(dendextend)

Variation in koala microbiomes within and between individuals: effect of body region and captivity status

Here we wish to reproduce figure 3: "Figure 3: Heatmap analysis of the most abundant bacterial genera detected across all samples.".

The heatmap depicts the relative percentage of 16S rRNA gene sequences assigned to each bacterial genus (y axis) across the 8 samples analysed (x axis). The heatmap colors represent the relative percentage of the microbial genus assignments within each sample. Square colors shifted towards bright blue indicate higher abundance. The relative abundance values of each genus for each sample are reported in Suppl. Tab. 4.

The data

The data was shared by Alfano, Niccolo. It shows for each genus of bacteria detected the relative abundance in the different samples used (eye, mouth, rectum, faeces of 2 koalas). Please keep in mind that the sum of the abundances of the genera could be less than 100%, cause the genera with an abundance <0.1% of the total read count were removed from the table to simplify the visualization of the results.

# koala_gut_genes <- read.csv("Figure 3_table.csv")
# rownames(koala_gut_genes) <- koala_gut_genes[,1]
# koala_gut_genes <- koala_gut_genes[,-1]
# http://r-pkgs.had.co.nz/data.html#data-data
# devtools::use_data(koala_gut_genes)


library(heatmaplyExamples)
data(koala_gut_genes)
head(koala_gut_genes)

heatmaply

Note that the color palette used here is not linear in the data.

library(heatmaply)
library(RColorBrewer)
library(scales) # for using a scaling of the colors which is similar to what appeared in the paper.

# display.brewer.all()
black_blue_fun <- gradient_n_pal(c("black", "royalblue1"), values = rescale(c(0,1:5,10,15,20,30,50,60,70,80,100)))
black_blue <- black_blue_fun(seq(0,1,length.out = 100))

heatmaply(koala_gut_genes, dendrogram=FALSE,
          col = black_blue, limits = c(0,100))

We can have the same heatmap but using the viridis color palette:

library(viridis)
viridis_fun <- gradient_n_pal(viridis(100), values = rescale(c(0,1:5,10,15,20,30,50,60,70,80,100)))
viridis_cols <- viridis_fun(seq(0,1,length.out = 100))

heatmaply(koala_gut_genes, dendrogram=FALSE,
          col = viridis_cols, limits = c(0,100))

And the same can be done, but with adding dendrograms and ordering them:

heatmaply(koala_gut_genes, 
          col = viridis_cols, limits = c(0,100))

sessionInfo

sessionInfo()


talgalili/heatmaplyExamples documentation built on May 23, 2019, 7:36 a.m.