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)
Some problems of SSLC ( High School ) before outputs and after outputs

Some problems of SSLC ( High School ) before outputs and after outputs 1] A Python program and its output (output1) while running the program is given

Fayas Noushad 3 Dec 01, 2021
The official colors of the FAU as matplotlib/seaborn colormaps

FAU - Colors The official colors of Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU) as matplotlib / seaborn colormaps. We support the old colo

Machine Learning and Data Analytics Lab FAU 9 Sep 05, 2022
Set of matplotlib operations that are not trivial

Matplotlib Snippets This repository contains a set of matplotlib operations that are not trivial. Histograms Histogram with bins adapted to log scale

Raphael Meudec 1 Nov 15, 2021
WhatsApp Chat Analyzer is a WebApp and it can be used by anyone to analyze their chat. 😄

WhatsApp-Chat-Analyzer You can view the working project here. WhatsApp chat Analyzer is a WebApp where anyone either tech or non-tech person can analy

Prem Chandra Singh 26 Nov 02, 2022
Create artistic visualisations with your exercise data (Python version)

strava_py Create artistic visualisations with your exercise data (Python version). This is a port of the R strava package to Python. Examples Facets A

Marcus Volz 53 Dec 28, 2022
LabGraph is a a Python-first framework used to build sophisticated research systems with real-time streaming, graph API, and parallelism.

LabGraph is a a Python-first framework used to build sophisticated research systems with real-time streaming, graph API, and parallelism.

MLH Fellowship 7 Oct 05, 2022
Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advanced practical bioinformatics and its applications globally.

-Nyokong. Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advance

4 Aug 04, 2022
Joyplots in Python with matplotlib & pandas :chart_with_upwards_trend:

JoyPy JoyPy is a one-function Python package based on matplotlib + pandas with a single purpose: drawing joyplots (a.k.a. ridgeline plots). The code f

Leonardo Taccari 462 Jan 02, 2023
This tool is designed to help administrators get an overview of their Active Directory structure.

This tool is designed to help administrators get an overview of their Active Directory structure. In the group view you can see all elements of an AD (OU, USER, GROUPS, COMPUTERS etc.). In the user v

deexno 2 Oct 30, 2022
nvitop, an interactive NVIDIA-GPU process viewer, the one-stop solution for GPU process management

An interactive NVIDIA-GPU process viewer, the one-stop solution for GPU process management.

Xuehai Pan 1.3k Jan 02, 2023
Interactive Dashboard for Visualizing OSM Data Change

Dashboard and intuitive data downloader for more interactive experience with interpreting osm change data.

1 Feb 20, 2022
Scientific Visualization: Python + Matplotlib

An open access book on scientific visualization using python and matplotlib

Nicolas P. Rougier 8.6k Dec 31, 2022
Quickly and accurately render even the largest data.

Turn even the largest data into images, accurately Build Status Coverage Latest dev release Latest release Docs Support What is it? Datashader is a da

HoloViz 2.9k Dec 28, 2022
Python package to Create, Read, Write, Edit, and Visualize GSFLOW models

pygsflow pyGSFLOW is a python package to Create, Read, Write, Edit, and Visualize GSFLOW models API Documentation pyGSFLOW API documentation can be fo

pyGSFLOW 21 Dec 14, 2022
Regress.me is an easy to use data visualization tool powered by Dash/Plotly.

Regress.me Regress.me is an easy to use data visualization tool powered by Dash/Plotly. Regress.me.-.Google.Chrome.2022-05-10.15-58-59.mp4 Get Started

Amar 14 Aug 14, 2022
Draw tree diagrams from indented text input

Draw tree diagrams This repository contains two very different scripts to produce hierarchical tree diagrams like this one: $ ./classtree.py collectio

Luciano Ramalho 8 Dec 14, 2022
This GitHub Repository contains Data Analysis projects that I have completed so far! While most of th project are focused on Data Analysis, some of them are also put here to show off other skills that I have learned.

Welcome to my Data Analysis projects page! This GitHub Repository contains Data Analysis projects that I have completed so far! While most of th proje

Kyle Dini 1 Jan 31, 2022
Personal IMDB Graphs with Bokeh

Personal IMDB Graphs with Bokeh Do you like watching movies and also rate all of them in IMDB? Would you like to look at your IMDB stats based on your

2 Dec 15, 2021
Flow-based visual scripting for Python

A simple visual node editor for Python Ryven combines flow-based visual scripting with Python. It gives you absolute freedom for your nodes and a simp

Leon Thomm 3.1k Jan 06, 2023
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 03, 2023