Skip to contents
library(ComplexHeatmap)
#> Loading required package: grid
#> ========================================
#> ComplexHeatmap version 2.22.0
#> Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
#> Github page: https://github.com/jokergoo/ComplexHeatmap
#> Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
#> 
#> If you use it in published research, please cite either one:
#> - Gu, Z. Complex Heatmap Visualization. iMeta 2022.
#> - Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
#>     genomic data. Bioinformatics 2016.
#> 
#> 
#> The new InteractiveComplexHeatmap package can directly export static 
#> complex heatmaps into an interactive Shiny app with zero effort. Have a try!
#> 
#> This message can be suppressed by:
#>   suppressPackageStartupMessages(library(ComplexHeatmap))
#> ========================================
library(pheatmap)
#> 
#> Attaching package: 'pheatmap'
#> The following object is masked from 'package:ComplexHeatmap':
#> 
#>     pheatmap
library(gplots)
#> 
#> Attaching package: 'gplots'
#> The following object is masked from 'package:stats':
#> 
#>     lowess
library(ggalign)
#> Loading required package: ggplot2
set.seed(123)
n <- 1000
mat <- matrix(rnorm(n * n), nrow = n)

A simple heatmap.

bench::mark(
    "heatmap()" = {
        pdf(NULL)
        heatmap(mat, Rowv = NA, Colv = NA)
        dev.off()
        NULL
    },
    "heatmap.2()" = {
        pdf(NULL)
        heatmap.2(mat, dendrogram = "none", trace = "none")
        dev.off()
        NULL
    },
    "Heatmap()" = {
        pdf(NULL)
        draw(Heatmap(mat,
            cluster_rows = FALSE, cluster_columns = FALSE,
            use_raster = TRUE
        ))
        dev.off()
        NULL
    },
    "pheatmap()" = {
        pdf(NULL)
        pheatmap(mat, cluster_rows = FALSE, cluster_cols = FALSE)
        dev.off()
        NULL
    },
    "ggalign()" = {
        pdf(NULL)
        print(ggheatmap(mat, filling = "raster"))
        dev.off()
        NULL
    }
)
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 5 × 6
#>   expression       min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>  <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 heatmap()   153.74ms 153.76ms     5.59   139.11MB     7.46
#> 2 heatmap.2()    2.49s    2.49s     0.401  224.23MB     1.61
#> 3 Heatmap()       4.1s     4.1s     0.244  805.38MB     2.93
#> 4 pheatmap()  628.63ms 628.63ms     1.59    124.1MB     1.59
#> 5 ggalign()      2.13s    2.13s     0.470    2.51GB    11.8

For heatmap with dendrogram

bench::mark(
    "heatmap()" = {
        pdf(NULL)
        heatmap(mat)
        dev.off()
        NULL
    },
    "heatmap.2()" = {
        pdf(NULL)
        heatmap.2(mat, trace = "none")
        dev.off()
        NULL
    },
    "Heatmap()" = {
        pdf(NULL)
        draw(Heatmap(mat,
            row_dend_reorder = FALSE, column_dend_reorder = FALSE,
            use_raster = TRUE
        ))
        dev.off()
        NULL
    },
    "pheatmap()" = {
        pdf(NULL)
        pheatmap(mat)
        dev.off()
        NULL
    },
    "ggalign()" = {
        pdf(NULL)
        print(ggheatmap(mat, filling = "raster") +
            anno_top() + align_dendro() +
            anno_right() + align_dendro())
        dev.off()
        NULL
    }
)
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#> 'magick' package is suggested to install to give better rasterization.
#> 
#> Set `ht_opt$message = FALSE` to turn off this message.
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 5 × 6
#>   expression       min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>  <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 heatmap()      2.92s    2.92s     0.343  173.72MB    2.06 
#> 2 heatmap.2()    2.73s    2.73s     0.367  223.41MB    2.20 
#> 3 Heatmap()      5.23s    5.23s     0.191    1.53GB    2.10 
#> 4 pheatmap()     2.24s    2.24s     0.447  177.53MB    0.894
#> 5 ggalign()      4.64s    4.64s     0.216    2.58GB    4.74