library(heatmaply)
library(dendextend)

1 Tissue- and time-dependent transcription in Ixodes ricinus salivary glands and midguts when blood feeding on the vertebrate host

Here we wish to reproduce figure 3: “Figure 3: Heat map of normalized RPKM data from the salivary glands (SG) and midguts (MG) of nymphal and adult Ixodes ricinus fed for different periods of time.”.

The Z score represents the deviation from the mean by standard deviation units. For other details, please see the Figure 2 legend.

Figure 2 legend: A box plot was constructed using normalized reads per kilobase per million (RPKM) values for CDS with a total RPKM (considering the reads of all ten libraries) of 50 or larger to avoid inclusion of poorly expressed contigs. The normalized RPKM values (maximum 100) for ten different libraries from Ixodes ricinus are as follows: the first two numbers indicate the time point of organ collection from 0–12h (12), 12–24h (24), or 24–36h (36). Organs were either salivary glands (SG) or midguts (MG) and developmental stage was either nymphs (N) or adults (A). For more details, please consult the methods.

1.1 heatmap.2 of the figure

The data and code for this plot was shared by Ribeiro, Jose (NIH/NIAID) [E]

# rpkm50 <- read.delim("rpkm-50.txt",sep="\t",header=TRUE,dec=".",stringsAsFactors = FALSE,strip.white = TRUE)
### saveRDS(rpkm50, "data\\rpkm50.rda")
# http://r-pkgs.had.co.nz/data.html#data-data
# devtools::use_data(rpkm50)


library(heatmaplyExamples)
data(rpkm50)
head(rpkm50)
#>     X12SG_N   X24SG_N   X12SG_A    X24SG_A    X36SG_A      X12MG_N
#> 1 235517.30 201172.23 95552.130 76629.5037 67257.2264 1.575864e+05
#> 2 219038.88 177905.38 81058.734 64990.6312 59070.8028 1.565105e+05
#> 3 207777.50 177673.71 83810.362 67112.6247 58877.7816 1.392322e+05
#> 4  17133.35  37736.14 64136.750 47097.0685 84443.5747 5.659074e+00
#> 5  50284.25  25032.12  1415.041   377.7924   681.7187 5.899005e+00
#> 6  46039.79  43387.75  6213.151  3730.7482  2188.6810 2.961282e+01
#>        X24MG_N      X12MG_A      X24MG_A      X36MG_A
#> 1 138293.30600 77681.686190 73534.886550 107423.87800
#> 2 114443.08230 82331.577490 72390.858400 107230.81370
#> 3 121766.27670 68088.353640 64444.787530  94416.34896
#> 4     12.53498   117.556341    16.826781     25.36865
#> 5      0.00000   495.307428   311.971324      0.00000
#> 6     17.16098     1.387416     2.909895      0.00000
x <- as.matrix(rpkm50)
rc <- rainbow(nrow(x), start=0, end=.3)
cc <- rainbow(ncol(x), start=0, end=.3)
 
# pdf(file='heatmap-spearman.pdf')
hr <- hclust(as.dist(1-cor(t(x), method="spearman")), method="complete")# spearman clustering
hc <- hclust(as.dist(1-cor(x, method="spearman")), method="complete")# spearman clustering
library(gplots)
heatmap.2(x, col=bluered(75), Colv=as.dendrogram(hc), Rowv=as.dendrogram(hr), scale="row", key=T, keysize=1.5,density.info="none", trace="none",cexCol=0.9, cexRow=0.9,labRow=NA, dendrogram="both") # Z scores

# dev.off()

1.2 heatmaply

We can now just take the last line, and replace heatmap.2 with heatmaply (the only missing part would be to have the dendrogram to the left instead of the right)

library(heatmaply)
heatmaply(x, col=bluered(75), Colv=as.dendrogram(hc), Rowv=as.dendrogram(hr), scale="row",
          key=T, keysize=1.5,density.info="none", trace="none",
          cexCol=0.9, cexRow=0.9 ,
          labRow=NA, dendrogram="both"
          ) # Z scores
# heatmaply(x[1:100,])
# heatmaply(x[1:100,], labRow=NA)
# heatmaply(x[1:100,], # col=bluered(75), scale="row",
#           # key=T, keysize=1.5,density.info="none", trace="none",
#           cexCol=0.9,
#           # fontsize_row=.9,
#           # cexRow=0.9 ,
#           # labRow=NA,
#           dendrogram="both"
#           )

2 sessionInfo

sessionInfo()
#> R version 3.4.1 (2017-06-30)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255   
#> [3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C                  
#> [5] LC_TIME=Hebrew_Israel.1255    
#> 
#> attached base packages:
#> [1] parallel  stats     graphics  grDevices datasets  utils     methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] scales_0.5.0            RColorBrewer_1.1-2     
#>  [3] limma_3.22.7            ALL_1.7.1              
#>  [5] Biobase_2.26.0          BiocGenerics_0.12.1    
#>  [7] dendextend_1.6.0        glmnet_2.0-10          
#>  [9] foreach_1.4.3           Matrix_1.2-10          
#> [11] bindrcpp_0.2            heatmaplyExamples_0.2.0
#> [13] knitr_1.16              gplots_3.0.1           
#> [15] heatmaply_0.11.0        viridis_0.4.0          
#> [17] viridisLite_0.2.0       plotly_4.7.1           
#> [19] ggplot2_2.2.1.9000      installr_0.19.0        
#> [21] stringr_1.2.0          
#> 
#> loaded via a namespace (and not attached):
#>  [1] httr_1.2.1         tidyr_0.6.3        jsonlite_1.5      
#>  [4] gtools_3.5.0       shiny_1.0.3        assertthat_0.2.0  
#>  [7] stats4_3.4.1       yaml_2.1.14        robustbase_0.92-7 
#> [10] backports_1.1.0    lattice_0.20-35    glue_1.1.1        
#> [13] digest_0.6.12      colorspace_1.3-2   httpuv_1.3.5      
#> [16] htmltools_0.3.6    plyr_1.8.4         devtools_1.13.2   
#> [19] pkgconfig_2.0.1    xtable_1.8-2       purrr_0.2.2.2     
#> [22] mvtnorm_1.0-6      gdata_2.18.0       whisker_0.3-2     
#> [25] tibble_1.3.4       mgcv_1.8-17        withr_2.0.0       
#> [28] nnet_7.3-12        lazyeval_0.2.0     mime_0.5          
#> [31] magrittr_1.5       mclust_5.3         memoise_1.1.0     
#> [34] evaluate_0.10.1    nlme_3.1-131       MASS_7.3-47       
#> [37] class_7.3-14       tools_3.4.1        registry_0.3      
#> [40] data.table_1.10.4  trimcluster_0.1-2  kernlab_0.9-25    
#> [43] munsell_0.4.3      cluster_2.0.6      fpc_2.1-10        
#> [46] compiler_3.4.1     caTools_1.17.1     rlang_0.1.2       
#> [49] grid_3.4.1         iterators_1.0.8    htmlwidgets_0.9   
#> [52] crosstalk_1.0.0    labeling_0.3       bitops_1.0-6      
#> [55] rmarkdown_1.6      gtable_0.2.0       codetools_0.2-15  
#> [58] flexmix_2.3-14     reshape2_1.4.2     TSP_1.1-5         
#> [61] R6_2.2.2           seriation_1.2-2    gridExtra_2.2.1   
#> [64] prabclus_2.2-6     dplyr_0.7.3.9000   bindr_0.1         
#> [67] rprojroot_1.2      KernSmooth_2.23-15 modeltools_0.2-21 
#> [70] stringi_1.1.5      Rcpp_0.12.12       gclus_1.3.1       
#> [73] DEoptimR_1.0-8     diptest_0.75-7