Interactive Cluster Heat Maps Using 'plotly'

Create interactive cluster 'heatmaps' that can be saved as a stand-alone HTML file, embedded in 'R Markdown' documents or in a 'Shiny' apps, and available in the 'RStudio' viewer pane, . Hover the mouse pointer over a cell to show details or drag a rectangle to zoom. A 'heatmap' is a popular graphical method for visualizing high-dimensional data, in which a table of numbers are encoded as a grid of colored cells. The rows and columns of the matrix are ordered to highlight patterns and are often accompanied by 'dendrograms'. 'Heatmaps' are used in many fields for visualizing observations, correlations, missing values patterns, and more. Interactive 'heatmaps' allow the inspection of specific value by hovering the mouse over a cell, as well as zooming into a region of the 'heatmap' by dragging a rectangle around the relevant area. This work is based on the 'ggplot2' and 'plotly.js' engine. It produces similar 'heatmaps' as 'heatmap.2' or 'd3heatmap', with the advantage of speed ('plotly.js' is able to handle larger size matrix), the ability to zoom from the 'dendrogram' panes, and the placing of factor variables in the sides of the 'heatmap'.


Table of contents:

This package is still under active development. If you have features you would like to have added, please submit your suggestions (and bug-reports) at: https://github.com/talgalili/heatmaply/issues

A heatmap is a popular graphical method for visualizing high-dimensional data, in which a table of numbers are encoded as a grid of colored cells. The rows and columns of the matrix are ordered to highlight patterns and are often accompanied by dendrograms. Heatmaps are used in many fields for visualizing observations, correlations, missing values patterns, and more.

Interactive heatmaps allow the inspection of specific value by hovering the mouse over a cell, as well as zooming into a region of the heatmap by draging a rectangle around the relevant area.

This work is based on the ggplot2 and plotly.js engine. It produces similar heatmaps as d3heatmap, with the advatange of speed (plotly.js is able to handle larger size matrix), and the ability to zoom from the dendrogram.

To install the stable version on CRAN:

install.packages('heatmaply')

To install the latest ("cutting-edge") GitHub version run:

 
# good packages to install for this to work smoothly:
 
install.packages("Rcpp", "ggplot2","munsell","htmltools","DBI","assertthat","gridExtra",
'devtools',"fpc","TSP","registry","gclus","gplots","RColorBrewer",
"stringr","labeling","yaml")
 
# You'll need devtools
install.packages.2 <- function (pkg) if (!require(pkg)) install.packages(pkg);
install.packages.2('devtools')
# make sure you have Rtools installed first! if not, then run:
#install.packages('installr'); install.Rtools()
 
devtools::install_github("ropensci/plotly") # you will probably benefit from the latest version of plotly
devtools::install_github('talgalili/heatmaply')

And then you may load the package using:

library("heatmaply")

Quick example:

library(heatmaply)
heatmaply(mtcars, k_row = 3, k_col = 2)

For more (interactive) examples see the online vignette on CRAN

This package is thanks to the amazing work done by MANY people in the open source community. Beyond the many people working on the pipeline of R, thanks should go to the plotly team, and especially to Carson Sievert and others working on the R package of plotly. Also, many of the design elements were inspired by the work done on heatmap, heatmap.2 and d3heatmap, so special thanks goes to the R core team, Gregory R. Warnes, and Joe Cheng from RStudio. The dendrogram side of the package is based on the work in dendextend, in which special thanks should go to Andrie de Vries for his original work on bringing dendrograms to ggplot2 (which evolved into the richer ggdend objects, as implemented in dendextend).

You are welcome to:

You can see the most recent changes to the package in the NEWS.md file

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

News

heatmaply 0.6.0 (2016-11-05)

  • heatmaply - * added row_side_colors to allow non-numeric values in the sidebar of the heatmap, similar to RowSideColors in gplots::heatmap.2 (RowSideColors also works in heatmaply). Props goes to Alanocallaghan for his work on this. * added a proper margins parameter. * grid_color now works (thanks to a hack of using geom_hline and geom_vline instead of heom_tile(..., color) in ggplot_heatmap ) * added branches_lwd - to control the width of the dendrograms' width.

heatmaply 0.5.0 (2016-08-04)

  • is.heatmapr
  • ggheatmap - first try. (not working well enough yet. The proportions of the elements are not good)
  • heatmaply
    • key.title - a parameter to control the main title of the color key. (feature request by John Rizk)

heatmaply 0.4.0 (2016-07-15)

  • heatmaply
    • grid_color - control the color of the heatmap grid. This is currently not working until this feature will be added by plotly.
    • hover over dendrogram now returns the height.
    • colors can now also accept a function (and will use it to produce 256 colors)
  • heatmapr
    • seriate - character indicating the method of matrix sorting (default: "OLO"). This uses the seriation package.
    • srtRow, srtCol - add legacy support for these parameters (they are passed to row_text_angle and column_text_angle)
    • hide_colorbar - controls if the color bar should be hidden.
    • xlab, ylab - add titles to the x and y axis.

heatmaply 0.3.2 (2016-05-26)

  • heatmaply 0.3.2 - first CRAN release!
  • http -> https

heatmaply 0.3.1 (2016-05-26)

  • fix minor typos.

heatmaply 0.3.0 (2016-05-25)

  • heatmaply
    • Now works with Rowv=F and Colv=F (by introducing a new un-exported function: heatmap_subplot_from_ggplotly)
    • Remove space between the heatmap and dendrograms (via: coord_cartesian(expand = FALSE) and coord_flip(expand = FALSE))
    • Added the margin parameter (to control the distance between the heatmap and the dendrograms.)
    • Added row_text_angle and column_text_angle (with srtRow and srtCol for backward compatibility with gplots::heatmap.2). Fix #3
  • fix #2 : Error: Don't know how to add scale_fill_gradient_fun to a plot by moving "scale_fill_gradient_fun" after "..." (I may change this parameter's name later)
  • heatmaply now has a basic vignette.

heatmaply 0.2.1 (2016-05-23)

  • fix various import issues that caused warnings with devtools::check()

heatmaply 0.2.0 (2016-05-23)

  • More control over colors in heatmaply via the new parameters: colours, limits, na.value, and scale_colour_gradient_fun.
  • first attempts at row_dend_left (although this is not yet working.)
  • dendrograms are now presented without axes text.
  • passing scale (= "row" or "column") works again.

heatmaply 0.1.0 (2016-05-14)

  • First (very rough) version. It has a minimal working example, as well as MANY things to fix/tweak/adjust.

TODO:

  • add bars for extra categories

  • remove unneeded code from d3heatmap

  • add many options for controlling the heatmap "as it should be"

  • implement all relevant options streight to heatmaply.

  • ggheatmap?

  • Expose widths and heights from heatmap_subplot_from_ggplotly to heatmaply

  • create colors from RcolorBrewer

  • write example for using seriation+dendextend for heatmaps.

  • add seriation to imports

  • Show the following example for using seriation:

require(seriation) require(dendextend)

"GW", "OLO"

d <- dist(USArrests[1:15,]) dend <- as.dendrogram(hclust(d, method = "ave")) par(mfrow = c(1,2)) plot(dend, main = "default")

seriate(cophenetic(dend), method = "OLO", control = list(hclust = as.hclust(dend)))

the downside in using cophenetic is that seriate has to go through running hclust all over again

but we'll just have to accept it...

o <- seriate(d, method = "GW", control = list(hclust = as.hclust(dend)) ) get_order(o) labels(cophenetic(dend))[get_order(o)] d2 <- rotate(dend, order = rev(labels(d)[get_order(o)])) plot(d2, main = "GW")

o <- seriate(d, method = "OLO", control = list(hclust = as.hclust(dend)) ) d3 <- rotate(dend, order = rev(labels(d)[get_order(o)]))

require(heatmaply) heatmaply(USArrests[1:15,], Rowv = d2) heatmaply(USArrests[1:15,], Rowv = d3) heatmaply(USArrests[1:15,], Rowv = dend)

hmap(USArrests[1:15,])

identical(seriate(d, method = "OLO"), seriate(d, method = "OLO", control = list(hclust = as.hclust(dend)) )) get_order(seriate(d, method = "OLO")) get_order(seriate(d, method = "OLO", control = list(hclust = hclust(d, method = "sing")) )) # this works :)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("heatmaply")

0.8.2 by Tal Galili, 6 days ago


https://cran.r-project.org/package=heatmaply, https://github.com/talgalili/heatmaply/, https://www.r-statistics.com/tag/heatmaply/


Report a bug at https://github.com/talgalili/heatmaply/issues


Browse source code at https://github.com/cran/heatmaply


Authors: Tal Galili [aut, cre, cph] (https://www.r-statistics.com), Jonathan Sidi [ctb] (https://github.com/yonicd), Alan Ocallaghan [ctb] (https://github.com/Alanocallaghan), Yoav Benjamini [ths]


Documentation:   PDF Manual  


GPL-2 | GPL-3 license


Imports ggplot2, dendextend, magrittr, reshape2, scales, seriation, utils, stats, grDevices, colorspace, RColorBrewer, GGally, htmlwidgets

Depends on plotly, viridis

Suggests knitr, rmarkdown, gplots


Suggested by dendextend.


See at CRAN