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)
1900-2016 Olympic Data Analysis in Python by plotting different graphs

🔥 Olympics Data Analysis 🔥 In Data Science field, there is a big topic before creating a model for future prediction is Data Analysis. We can find o

Sayan Roy 1 Feb 06, 2022
PanGraphViewer -- show panenome graph in an easy way

PanGraphViewer -- show panenome graph in an easy way Table of Contents Versions and dependences Desktop-based panGraphViewer Library installation for

16 Dec 17, 2022
The windML framework provides an easy-to-use access to wind data sources within the Python world, building upon numpy, scipy, sklearn, and matplotlib. Renewable Wind Energy, Forecasting, Prediction

windml Build status : The importance of wind in smart grids with a large number of renewable energy resources is increasing. With the growing infrastr

Computational Intelligence Group 125 Dec 24, 2022
Customizing Visual Styles in Plotly

Customizing Visual Styles in Plotly Code for a workshop originally developed for an Unconference session during the Outlier Conference hosted by Data

Data Design Dimension 9 Aug 03, 2022
Design your own matplotlib stylefile interactively

Tired of playing with font sizes and other matplotlib parameters every time you start a new project or write a new plotting function? Want all you plots have the same style? Use matplotlib configurat

yobi byte 207 Dec 08, 2022
Fast 1D and 2D histogram functions in Python

About Sometimes you just want to compute simple 1D or 2D histograms with regular bins. Fast. No nonsense. Numpy's histogram functions are versatile, a

Thomas Robitaille 237 Dec 18, 2022
Datapane is the easiest way to create data science reports from Python.

Datapane Teams | Documentation | API Docs | Changelog | Twitter | Blog Share interactive plots and data in 3 lines of Python. Datapane is a Python lib

Datapane 744 Jan 06, 2023
Open-source demos hosted on Dash Gallery

Dash Sample Apps This repository hosts the code for over 100 open-source Dash apps written in Python or R. They can serve as a starting point for your

Plotly 2.7k Jan 07, 2023
TensorDebugger (TDB) is a visual debugger for deep learning. It extends TensorFlow with breakpoints + real-time visualization of the data flowing through the computational graph

TensorDebugger (TDB) is a visual debugger for deep learning. It extends TensorFlow (Google's Deep Learning framework) with breakpoints + real-time visualization of the data flowing through the comput

Eric Jang 1.4k Dec 15, 2022
University of Missouri - Kansas City: CS451R: Capstone

CS451RC University of Missouri - Kansas City: CS451R: Capstone Installation cd git clone https://github.com/ala2q6/CS451RC.git cd CS451RC pip3 instal

Alex Arbuckle 1 Nov 17, 2021
Visualizations of some specific solutions of different differential equations.

Diff_sims Visualizations of some specific solutions of different differential equations. Heat Equation in 1 Dimension (A very beautiful and elegant ex

2 Jan 13, 2022
Focus on Algorithm Design, Not on Data Wrangling

The dataTap Python library is the primary interface for using dataTap's rich data management tools. Create datasets, stream annotations, and analyze model performance all with one library.

Zensors 37 Nov 25, 2022
A Jupyter - Leaflet.js bridge

ipyleaflet A Jupyter / Leaflet bridge enabling interactive maps in the Jupyter notebook. Usage Selecting a basemap for a leaflet map: Loading a geojso

Jupyter Widgets 1.3k Dec 27, 2022
Fastest Gephi's ForceAtlas2 graph layout algorithm implemented for Python and NetworkX

ForceAtlas2 for Python A port of Gephi's Force Atlas 2 layout algorithm to Python 2 and Python 3 (with a wrapper for NetworkX and igraph). This is the

Bhargav Chippada 227 Jan 05, 2023
A deceptively simple plotting library for Streamlit

🍅 Plost A deceptively simple plotting library for Streamlit. Because you've been writing plots wrong all this time. Getting started pip install plost

Thiago Teixeira 192 Dec 29, 2022
Tools for writing, submitting, debugging, and monitoring Storm topologies in pure Python

Petrel Tools for writing, submitting, debugging, and monitoring Storm topologies in pure Python. NOTE: The base Storm package provides storm.py, which

AirSage 247 Dec 18, 2021
script to generate HeN ipfs app exports of GLSL shaders

HeNerator A simple script to generate HeN ipfs app exports from any frag shader created with: GlslViewer GlslEditor The Book of Shaders glslCanvas VS

Patricio Gonzalez Vivo 22 Dec 21, 2022
Visualize tensors in a plain Python REPL using Sparklines

Visualize tensors in a plain Python REPL using Sparklines

Shawn Presser 43 Sep 03, 2022
visualize_ML is a python package made to visualize some of the steps involved while dealing with a Machine Learning problem

visualize_ML visualize_ML is a python package made to visualize some of the steps involved while dealing with a Machine Learning problem. It is build

Ayush Singh 164 Dec 12, 2022
Uniform Manifold Approximation and Projection

UMAP Uniform Manifold Approximation and Projection (UMAP) is a dimension reduction technique that can be used for visualisation similarly to t-SNE, bu

Leland McInnes 6k Jan 08, 2023