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/ComplexHeatmap@7e066ad)
    

    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)
Calendar heatmaps from Pandas time series data

Note: See MarvinT/calmap for the maintained version of the project. That is also the version that gets published to PyPI and it has received several f

Martijn Vermaat 195 Dec 22, 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
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
Splore - a simple graphical interface for scrolling through and exploring data sets of molecules

Scroll through and exPLORE molecule sets The splore framework aims to offer a si

null 3 Jun 18, 2022
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
Extract data from ThousandEyes REST API and visualize it on your customized Grafana Dashboard.

ThousandEyes Grafana Dashboard Extract data from the ThousandEyes REST API and visualize it on your customized Grafana Dashboard. Deploy Grafana, Infl

Flo Pachinger 16 Nov 26, 2022
Domain Connectivity Analysis Tools to analyze aggregate connectivity patterns across a set of domains during security investigations

DomainCAT (Domain Connectivity Analysis Tool) Domain Connectivity Analysis Tool is used to analyze aggregate connectivity patterns across a set of dom

DomainTools 34 Dec 9, 2022
Visualize your pandas data with one-line code

PandasEcharts 简介 基于pandas和pyecharts的可视化工具 安装 pip 安装 $ pip install pandasecharts 源码安装 $ git clone https://github.com/gamersover/pandasecharts $ cd pand

陈华杰 2 Apr 13, 2022
Visualize data of Vietnam's regions with interactive maps.

Plotting Vietnam Development Map This is my personal project that I use plotly to analyse and visualize data of Vietnam's regions with interactive map

null 1 Jun 26, 2022
Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts

Data-FX Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts Currently, there are only 2 chart option

Landon Ferguson 20 Nov 21, 2022
Generate graphs with NetworkX, natively visualize with D3.js and pywebview

webview_d3 This is some PoC code to render graphs created with NetworkX natively using D3.js and pywebview. The main benifit of this approac

byt3bl33d3r 68 Aug 18, 2022
Extract and visualize information from Gurobi log files

GRBlogtools Extract information from Gurobi log files and generate pandas DataFrames or Excel worksheets for further processing. Also includes a wrapp

Gurobi Optimization 56 Nov 17, 2022
This is a web application to visualize various famous technical indicators and stocks tickers from user

Visualizing Technical Indicators Using Python and Plotly. Currently facing issues hosting the application on heroku. As soon as I am able to I'll like

null 4 Aug 4, 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
Epagneul is a tool to visualize and investigate windows event logs

epagneul Epagneul is a tool to visualize and investigate windows event logs. Dep

jurelou 190 Dec 13, 2022
This project is an Algorithm Visualizer where a user can visualize algorithms like Bubble Sort, Merge Sort, Quick Sort, Selection Sort, Linear Search and Binary Search.

Algo_Visualizer This project is an Algorithm Visualizer where a user can visualize common algorithms like "Bubble Sort", "Merge Sort", "Quick Sort", "

Rahul 4 Feb 7, 2022
WebApp served by OAK PoE device to visualize various streams, metadata and AI results

DepthAI PoE WebApp | Bootstrap 4 & Vue.js SPA Dashboard Based on dashmin (https:

Luxonis 6 Apr 9, 2022
A Python library created to assist programmers with complex mathematical functions

libmaths was created not only as a learning experience for me, but as a way to make mathematical models in seconds for Python users using mat

Simple 73 Oct 2, 2022
Automatically Visualize any dataset, any size with a single line of code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

AutoViz Automatically Visualize any dataset, any size with a single line of code. AutoViz performs automatic visualization of any dataset with one lin

AutoViz and Auto_ViML 1k Jan 2, 2023