Complex heatmaps are efficient to visualize associations between different sources of data sets and reveal potential patterns.

Overview

Make Complex Heatmaps

R-CMD-check codecov bioc bioc

Complex heatmaps are efficient to visualize associations between different sources of data sets and reveal potential patterns. Here the ComplexHeatmap package provides a highly flexible way to arrange multiple heatmaps and supports various annotation graphics.

The InteractiveComplexHeatmap package can directly export static complex heatmaps into an interactive Shiny app. Have a try!

Citation

Zuguang Gu, et al., Complex heatmaps reveal patterns and correlations in multidimensional genomic data, Bioinformatics, 2016

Install

ComplexHeatmap is available on Bioconductor, you can install it by:

if (!requireNamespace("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("ComplexHeatmap")

If you want the latest version, install it directly from GitHub:

library(devtools)
install_github("jokergoo/ComplexHeatmap")

Usage

Make a single heatmap:

Heatmap(mat, ...)

A single Heatmap with column annotations:

ha = HeatmapAnnotation(df = anno1, anno_fun = anno2, ...)
Heatmap(mat, ..., top_annotation = ha)

Make a list of heatmaps:

Heatmap(mat1, ...) + Heatmap(mat2, ...)

Make a list of heatmaps and row annotations:

ha = HeatmapAnnotation(df = anno1, anno_fun = anno2, ..., which = "row")
Heatmap(mat1, ...) + Heatmap(mat2, ...) + ha

Documentation

The full documentations are available at https://jokergoo.github.io/ComplexHeatmap-reference/book/ and the website is at https://jokergoo.github.io/ComplexHeatmap.

Blog posts

There are following blog posts focusing on specific topics:

Examples

Visualize Methylation Profile with Complex Annotations

complexheatmap_example4

Correlations between methylation, expression and other genomic features

complexheatmap_example3

Visualize Cell Heterogeneity from Single Cell RNASeq

complexheatmap_example2

Making Enhanced OncoPrint

complexheatmap_example1

UpSet plot

3D heatmap

image

License

MIT @ Zuguang Gu

Comments
  • error: You should have at least two distinct break values in complexheatmap

    error: You should have at least two distinct break values in complexheatmap

    Hi @jokergoo, Thanks to develop this greate tools, The matrix i put in Heatmap sparked the error like below, error: You should have at least two distinct break values in complexheatmap Why the error occurred when using the matrix to plot heatmap using complexheatmap R package. the original code showing below,

    Heatmap(as.matrix(m))
    

    The matrix displaying below,

    image

    Any advice would be appricated

    opened by honghh2018 27
  • split on columns?

    split on columns?

    Hi,

    I looked at the help page for Heatmap, it seems only supports split on rows, and there is a gap parameter for it. Is it possible to split on columns as well?

    A more detailed question is: when I do a supervised-clustering, I want to first split the columns (samples) into say 3 pre-defined subgroups first, and then do clustering within each subgroup for columns and do a k-means for all rows. Is it possible?

    Now, I am manually arrange the data matrix into three distinct groups, and do a K means with the rows, and cluster_column=FALSE.

    Thanks, Ming

    opened by crazyhottommy 26
  • When cluster with too many rows, the heatmap is too dense, and the file size is large.

    When cluster with too many rows, the heatmap is too dense, and the file size is large.

    Hi,

    This is more like a general question. When making heatmap with too many rows, usually use EnrichedHeatmap with many (more than 10,000) genomic regions, the PDF size of the heatmap is very big (several MB). Computer becomes very slow when visualize it or when insert into powerpoint and Word. For other type of analysis, I usually use only top several hundred most variable rows to cluster.

    I know it is more of a visualization than making any real quantitative comparisons. Our eyes probably can not differentiate these many pixels. How to reduce the size of the PDF?

    Some time ago, I got a tip from this post

    Now for my heatmap power tip of the day, if you will: use the "useRaster=TRUE" parameter in your heatmap.2() call. Excellent extension by R developers since 2.13. But for some reason the R developers explicitly turn it off for interactive session windows, so you'll only see it in an exported file. (Unless you have a custom image() function which doesn't disable it, I did this.) It also makes the exported file hugely smaller, especially for PDFs.

    What it does is darn-near essential for nextgen coverage heatmaps -- it actually properly resamples the image as it down-sizes the image during export. Without useRaster=TRUE, image() creates a zillion tiny rectangles to represent the heatmap, all pieced together right next to each other. When the display is fewer pixels/points high than the number of rows of data, it discretizes the data -- that is, it uses integer values for the rectangles. In many cases, especially onscreen, many rectangles fully overlap others, randomly obscuring the real patterns, and often blunting your otherwise cool-looking signal.

    useRaster=TRUE is only for heatmap.2 or internally image(). Is there a way to specify it in ComplexHeatmaps or how do you usually deal with this situation?

    Thanks, Ming

    opened by crazyhottommy 25
  • `ComplexHeatmap::pheatmap()` cannot produce top annotations when called from within `do.call`.

    `ComplexHeatmap::pheatmap()` cannot produce top annotations when called from within `do.call`.

    Some of the logic within HeatmapAnnotation()'s system call check code breaks down when it is called within do.call(pheatmap, ...)

    library(ComplexHeatmap)
    
    mat <- matrix(rpois(30, 20), ncol=5)
    rownames(mat) <- paste0("gene", 1:6)
    colnames(mat) <- paste0("samp", 1:5)
    
    annotation_col <- data.frame(score = 1:5,
                                 row.names = colnames(mat))
    
    # Direct call works
    pheatmap(mat, annotation_col = annotation_col)
    
    # indirect call with do.call
    do.call(pheatmap, list(mat, annotation_col = annotation_col))
    > Error in as.character(scl[[1]]) : 
        cannot coerce type 'closure' to vector of type 'character'
    

    The error comes from this line, https://github.com/jokergoo/ComplexHeatmap/blob/a5cd974897746990d16843724d71822ccd771feb/R/HeatmapAnnotation-class.R#L161 and results from scl[[1]] being the function definition itself, rather than its symbolic name. Thus as.character() fails.

    I'm not sure of the best solution here, but it may help that is.symbol(scl[[1]]) evaluates to TRUE for direct calls but FALSE for indirect calls through do.call.

    opened by dtm2451 19
  • Error: invalid 'xscale' in viewport

    Error: invalid 'xscale' in viewport

    ComplexHeatmap::Heatmap(matrix(c(0, 0, 1, 1), nrow=2))
    

    gives

    Error in valid.viewport(x, y, width, height, just, gp, clip, mask, xscale,  :
      invalid 'xscale' in viewport
    
    opened by bersbersbers 18
  • column_split usage

    column_split usage

    Hi,

    I want to split the columns unevenly. I have 34 samples and want to split it to 8-26 in the oncoPrint. I tried to search the wiki, but I am unable to find the proper usage for that. It always gives me the error that "the number of columns should be equal to the ncol of matirx"

    Also I am using, column_order and column)split both, so should I define a list of column orders since I am splitting the matrix?

    You help is much appreciated.

    Thanks, Rashesh

    opened by Rashesh7 18
  • Apply customized dendrogram to heatmap

    Apply customized dendrogram to heatmap

    Hey, I was wondering how to apply my customized dendrogram to the heatmap. I first generated a heatmap with specified clustering method in Heatmap commend:

    Heatmap(matrix_new, cluster_columns =T, cluster_rows=F, clustering_distance_columns = "pearson", clustering_method_columns = "ward.D")

    Then, I customized the dendrogram using the following codes

    hc <- hclust(as.dist(1-cor(t(sample.norm[,1:18]),method="pearson")),method="ward.D") dd <- as.dendrogram(hc) dd.reorder = reorder(dd, c(rep(10, 22),rep(9,27),rep(1,49)), agglo.FUN = mean)

    When I plot the customized dendrogram, it did changed into the way I want. And I assigned the customized dendrogram to the heatmap I created at the first:

    Heatmap(matrix_new, cluster_columns = dd.reorder, cluster_rows=F)

    However, the dendrograms in two heatmaps did not change. I am not sure what went wrong, and come here for some help. Any advise?

    Thanks, Stingo

    opened by stingo93 16
  • Custom Heatmap Row Labels

    Custom Heatmap Row Labels

    Greetings!

    I was wondering if it is possible to add a table along the height of the heatmap to depict multiple pieces of information about the column? For instance, I want to show the gene locus number in one column, the gene name in a second, and what it is identified as in a different organism in a third column. I have gone through the how to web pages for the ComplexHeatmap package, and I saw nothing. Is what I am suggesting possible for your package? If not, do you have any suggestions as to how I might be able to implement this?

    Thank you very much for your time!

    enhancement 
    opened by FireBorn123 15
  • Not a validObject(): no slot of name

    Not a validObject(): no slot of name "subsetable"

    Hi jokergoo, I'm working on a new project and I make some complexheatmaps. However when I open the R project and I load the library {ComplexHeatmap}, I get these warnings:

    Warning messages:
    1: Not a validObject(): no slot of name "subsetable" for this object of class "HeatmapAnnotation" 
    2: Not a validObject(): no slot of name "subsetable" for this object of class "SingleAnnotation" 
    3: Not a validObject(): no slot of name "subsetable" for this object of class "AnnotationFunction" 
    4: Not a validObject(): no slot of name "subsetable" for this object of class "HeatmapAnnotation" 
    5: Not a validObject(): no slot of name "subsetable" for this object of class "SingleAnnotation" 
    6: Not a validObject(): no slot of name "subsetable" for this object of class "AnnotationFunction" 
    

    The problem appears only when I load the package inside this R project and only the first time I load it. In other R project I don't have it. Do you know why I have these warnings? I don't even understand what do they mean.

    I have the latest version of R (4.1.3) and ComplexHeatmap (2.10.0).

    opened by ShinyFabio 14
  • Freeze after first Heatmap()

    Freeze after first Heatmap()

    Thank you for putting together and maintaining ComplexHeatmap. I just got started with the github version 2.9.3 (July 29, 2021) on R Version 4.0.2. Heatmap() runs without any issue for the first heatmap. But, on trying to repeat this with the same matrix, R freezes. This occurs both with RStudio and from R Console.

    Here are some snippets from running devtools::session_info()

    - Session info -----------------------------------------------------------------------------------
     setting  value                       
     version  R version 4.0.2 (2020-06-22)
     os       Windows 10 x64              
     system   x86_64, mingw32             
     ui       RStudio                     
     language (EN)                        
     collate  English_United States.1252  
     ctype    English_United States.1252  
     tz       America/New_York            
     date     2021-07-29 
    
     ComplexHeatmap * 2.9.3    2021-07-29 [1] Github (jokergoo/[email protected])
    

    Thanks, Vishal

    opened by pseudorational 14
  • heatmap_legend_side does not moves the annotation legends

    heatmap_legend_side does not moves the annotation legends

    Hi,

    When we use the parameter heatmap_legend_side to move the legends to the bottom draw(ht, heatmap_legend_side = "bottom"), it only moves the legends from the onconprint, but not for annatations to the bottom.

    How can I do that? I would like to have all legends in the bottom. Thanks.

    image

    opened by tiagochst 14
  • Get nicer plot with anno_mark

    Get nicer plot with anno_mark

    Hello!

    Thanks for ComplexHeatmap!! I was wondering what's the best way to get something like B here (Alvisi G,et al. Multimodal single-cell profiling of intrahepatic cholangiocarcinoma defines hyperactivated Tregs as a potential therapeutic target. J Hepatol. 2022 Nov;77(5):1359-1372.): image

    I have a gene co-expression heatmap and I want to show selected genes in the areas of high correlation. Here is my attempt with anno_mark:

    position <- which(rownames(mat)%in%genes)
    
    row_an <- rowAnnotation(Genes = anno_mark(at = position,
                                               labels = rownames(mat)[position],
                                               labels_gp = gpar(fontsize = 6),
                                               link_width = unit(5, "mm"),
                                               padding = unit(1, "mm"),
                                               link_gp = gpar(lwd = 1),
                                              extend = unit(1, "mm")))
    
    ht.3 <- Heatmap(mat, name = "Spearman correlation",
                    column_names_gp = grid::gpar(fontsize = 0),
                    row_names_gp = grid::gpar(fontsize = 0),
                    right_annotation = row_an,
                    heatmap_legend_param = list(legend_direction = "horizontal")) 
    draw(ht.3, heatmap_legend_side = "bottom")
    

    where genes are the selected genes I want to plot.

    This is what I get: heat_corr

    The heatmap is a bit confusing. I tried to use anno_zoom or anno_textbox but would like to maintain the rows clustering and I would prefer not to split the rows.

    Is it doable?

    Thanks, Francesco

    opened by france-hub 0
  • Visually different heatmaps even though generated in the exact same way

    Visually different heatmaps even though generated in the exact same way

    So I have been trying to troubleshoot this issue I have run into when generating publication quality grouped heatmaps.

    I am attaching 3 heatmaps which are generated from three different matrices, but which are all generated in exactly the same way. The code to generate the heatmaps is also exactly the same ( it is one function iterated over the three matrices.)

    However, for some reason I have yet to understand, they have strikingly different 'pixel' size. This is visible directly in the in-line RStudio image device... as well as after exporting at 1200 DPI PNG files.

    Any ideas? I'm including the size of the data matrices for comparison:

    Heatmap 1: 875 columns x 2119 rows

    aaa_1

    Heatmap 2: 674 columns x 1743 rows

    aaa_2

    Heatmap 3: 241 ccolumns x 1780 rows

    aaa_3

    opened by RobertWhitener 0
  • How to make bars filled with more than two colors correctly in anno_numeric?

    How to make bars filled with more than two colors correctly in anno_numeric?

    ginfo: image

    anno209 <- rowAnnotation(
        log2fc1 = anno_numeric(ginfo$log2FC209 %>% nice_round(., digit=3), 
                               bg_gp = gpar(fill = ginfo$col209),
                               labels_gp = gpar(fontsize = letter_size),
                               bar_width = unit(1, "npc") - unit(2, "pt")), 
        annotation_name_rot = row_anno_rot,
        annotation_name_gp = gpar(fontsize = label_size, fontface = "bold"),
        width=unit(c(row_anno_width), "in"),
        annotation_name_offset = unit(c(row_anno_offset), "mm"),
        annotation_label = "log2FC 209_5 VS 313_1" 
      );
    

    I intended to have log2FC barplot as a row annotation using anno_numeric, fill the bars that are significantly (padj209 <= 0.05) upregulated (log2FC209 > 0) red, significantly (padj209 <= 0.05) downregulated (log2FC209 < 0) green, not significant (padj209 > 0.05) white. Based on the criteria, I have the color ready as col209. Using the code above, I got bar annotation as below:

    image

    Basically, it failed to add the color appropriately. Do you know how to fix it?

    Thank you very much, Wendy

    opened by guodudou 0
  • Can't Add Multiple Annotations to UpSet Plot: Error: Length of annotations differs.

    Can't Add Multiple Annotations to UpSet Plot: Error: Length of annotations differs.

    Dear Jokergoo, Congratulations on developing and maintaining this fantastic package. Easily one of my favourite R packages overall.

    I've recently stumbled across a frustrating error whilst trying to make an UpSet plot annotated with different intersect methods. For context, I've made this type of plot before (shown below), and in fact even recycled the code when trying to remake it this time. My problem is that I can make each UpSet plot (intersect, distinct, and union) separately fine (shown below), but when I tried to add them into the same plot I get the following error: "Error: Length of annotations differs. distict: 7, intersect: 11, union: 15" (notice also the little spelling mistake in "distict").

    ComplexHeatmap Issue-page-001

    And here is my code

    Sets <- list(
    Abd.Fem   = vector1,
    Glu.Fem    = vector2,
    Abd.Man  = vector3,
    Glu.Man   = vector4)
    UPSets.intersect <- make_comb_mat(Sets, mode = "intersect", min_set_size = 0)
    UPSets.intersect.distinct <- make_comb_mat(Sets, mode = "distinct", min_set_size = 0)
    UPSets.intersect.union <- make_comb_mat(Sets, mode = "union", min_set_size = 0)
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    Sets.Upset.Plot <-
    UpSet(t(UPSets.intersect.distinct[comb_degree(UPSets.intersect.distinct) > 0]),
          comb_order = order(-comb_size(UPSets.intersect.distinct[comb_degree(UPSets.intersect.distinct) > 0])),
          set_order = c("Abd.Fem","Glu.Fem","Abd.Man","Glu.Man"),
          pt_size = unit(5, "mm"),
          lwd = 3,
          bg_col = c("#f5e1e1","#f5e1e1","#e7f5fe","#e7f5fe"),
          right_annotation = rowAnnotation(
        "distict" = anno_barplot(comb_size(UPSets.intersect.distinct), 
            gp = gpar(fill = "black"), width = unit(1.5, "cm")), 
        "intersect" = anno_barplot(comb_size(UPSets.intersect), 
            gp = gpar(fill = "black"), width = unit(1.5, "cm")), 
        "union" = anno_barplot(comb_size(UPSets.intersect.union), 
            gp = gpar(fill = "black"), width = unit(1.5, "cm")), 
        gap = unit(2, "mm"), annotation_name_side = "bottom"))
    
    Error: Length of annotations differs. distict: 7, intersect: 11, union: 15
    
    

    Is it possible to plot these together, as last time, or does the data this time somehow make it impossible? I am using ComplexHeatmap version 2.15.1, downloaded from GitHub today. Your help is very much appreciated! Best wishes, Daniel

    opened by danphillips28 0
  • Remove white space between samples in Oncoprint

    Remove white space between samples in Oncoprint

    Hello, Thank you very much for this great package, I use it every time. I was looking to know if it would be possible to remove the white space between sample to get an oncoprint that looks like this ?

    oncoprint

    Thank you! Evan

    opened by eseffar 1
  • How to make the fill color in anno_barplot a gradient color like in heatmap

    How to make the fill color in anno_barplot a gradient color like in heatmap

    Hello, I am trying to make a barplot annotation. The values are between -1 and 1 and I would like to make the filling color gradient like in heatmap using colorRamp2(c(-1, 0, 1), c("green", "white", "red")), but it didn't work If I specify in Signature = anno_barplot(sinfo %>% pull(Signature), height = unit(1.2, "cm"), gp = gpar(fill = colorRamp2(c(-1, 0, 1), c("green", "white", "red")))) Do you have any suggestions? The purpose is to color the following barplots in gradient. image

    Thank you very much!

    opened by guodudou 0
Releases(1.99.4)
Import, visualize, and analyze SpiderFoot OSINT data in Neo4j, a graph database

SpiderFoot Neo4j Tools Import, visualize, and analyze SpiderFoot OSINT data in Neo4j, a graph database Step 1: Installation NOTE: This installs the sf

Black Lantern Security 42 Dec 26, 2022
Analysis and plotting for motor/prop/ESC characterization, thrust vs RPM and torque vs thrust

esc_test This is a Python package used to plot and analyze data collected for the purpose of characterizing a particular propeller, motor, and ESC con

Alex Spitzer 1 Dec 28, 2021
A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.

Visdom A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Python. Overview Concepts Setup Usage API To

FOSSASIA 9.4k Jan 07, 2023
Python wrapper for Synoptic Data API. Retrieve data from thousands of mesonet stations and networks. Returns JSON from Synoptic as Pandas DataFrame

☁ Synoptic API for Python (unofficial) The Synoptic Mesonet API (formerly MesoWest) gives you access to real-time and historical surface-based weather

Brian Blaylock 23 Jan 06, 2023
Attractors is a package for simulation and visualization of strange attractors.

attractors Attractors is a package for simulation and visualization of strange attractors. Installation The simplest way to install the module is via

Vignesh M 45 Jul 31, 2022
Visualize the bitcoin blockchain from your local node

Project Overview A new feature in Bitcoin Core 0.20 allows users to dump the state of the blockchain (the UTXO set) using the command dumptxoutset. I'

18 Sep 11, 2022
Type-safe YAML parser and validator.

StrictYAML StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification. Priorities: Beautiful API Re

Colm O'Connor 1.2k Jan 04, 2023
3D-Lorenz-Attractor-simulation-with-python

3D-Lorenz-Attractor-simulation-with-python Animação 3D da trajetória do Atrator de Lorenz, implementada em Python usando o método de Runge-Kutta de 4ª

Hevenicio Silva 17 Dec 08, 2022
Easily convert matplotlib plots from Python into interactive Leaflet web maps.

mplleaflet mplleaflet is a Python library that converts a matplotlib plot into a webpage containing a pannable, zoomable Leaflet map. It can also embe

Jacob Wasserman 502 Dec 28, 2022
a plottling library for python, based on D3

Hello August 2013 Hello! Maybe you're looking for a nice Python interface to build interactive, javascript based plots that look as nice as all those

Mike Dewar 1.4k Dec 28, 2022
A high performance implementation of HDBSCAN clustering. http://hdbscan.readthedocs.io/en/latest/

HDBSCAN Now a part of scikit-learn-contrib HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over va

Leland McInnes 91 Dec 29, 2022
A programming language built on top of Python to easily allow Swahili speakers to get started with programming without ever knowing English

pyswahili A programming language built over Python to easily allow swahili speakers to get started with programming without ever knowing english pyswa

Jordan Kalebu 72 Dec 15, 2022
Simple addon for snapping active object to mesh ground

Snap to Ground Simple addon for snapping active object to mesh ground How to install: install the Python file as an addon use shortcut "D" in 3D view

Iyad Ahmed 12 Nov 07, 2022
Squidpy is a tool for the analysis and visualization of spatial molecular data.

Squidpy is a tool for the analysis and visualization of spatial molecular data. It builds on top of scanpy and anndata, from which it inherits modularity and scalability. It provides analysis tools t

Theis Lab 251 Dec 19, 2022
https://there.oughta.be/a/macro-keyboard

inkkeys Details and instructions can be found on https://there.oughta.be/a/macro-keyboard In contrast to most of my other projects, I decided to put t

Sebastian Staacks 209 Dec 21, 2022
A small collection of tools made by me, that you can use to visualize atomic orbitals in both 2D and 3D in different aspects.

Orbitals in Python A small collection of tools made by me, that you can use to visualize atomic orbitals in both 2D and 3D in different aspects, and o

Prakrisht Dahiya 1 Nov 25, 2021
Simulation du problème de Monty Hall avec Python et matplotlib

Le problème de Monty Hall C'est un jeu télévisé où il y a trois portes sur le plateau de jeu. Seule une de ces portes cache un trésor. Il n'y a rien d

ETCHART YANG 1 Jan 06, 2022
NumPy and Pandas interface to Big Data

Blaze translates a subset of modified NumPy and Pandas-like syntax to databases and other computing systems. Blaze allows Python users a familiar inte

Blaze 3.1k Jan 01, 2023
Bar Chart of the number of Senators from each party who are up for election in the next three General Elections

Congress-Analysis Bar Chart of the number of Senators from each party who are up for election in the next three General Elections This bar chart shows

11 Oct 26, 2021
Package managers visualization

Software Galaxies This repository combines visualizations of major software package managers. All visualizations are available here: http://anvaka.git

Andrei Kashcha 1.4k Dec 22, 2022