Create interactive cluster 'heatmaps' that can be saved as a stand- alone HTML file, embedded in 'R Markdown' documents or in a 'Shiny' app, 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' to 'heatmap.2' 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:
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 d3heatmap (or the static heatmap.2 from gplots), with the advantage of more features such as speed (plotly.js is able to handle larger size matrix), sidebar annotation, and the ability to zoom from the dendrogram.
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
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.
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(c("Rcpp","ggplot2","munsell","htmltools","DBI","assertthat","gridExtra","digest","fpc","TSP","registry","gclus","gplots","RColorBrewer","stringr","labeling","yaml")) # You'll need devtoolsinstall.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 plotlydevtools::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
There are also more complex biological examples of using heatmaply in the R package heatmaplyExamples (hosted on github). Here are direct links for available examples:
You can save an interactive version of your heatmaply into an HTML file using the following code:
dir.create("folder")library(heatmaply)heatmaply(mtcars, file = "folder/heatmaply_plot.html")browseURL("folder/heatmaply_plot.html")
Similar code can be used for saving a static file (png/jpeg/pdf)
dir.create("folder")library(heatmaply)# Before the first time using this code you may need to first run:# webshot::install_phantomjs()heatmaply(mtcars, file = "folder/heatmaply_plot.png")browseURL("folder/heatmaply_plot.png")
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 people working on ggplot2 (Hadley Wickham, etc.) and plotly (Carson Sievert, etc.). 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).
The work on heatmaply was done by Tal Galili, Alan O'Callaghan, and Jonathan Sidi (mostly on shinyHeatmaply).
Funding: This work was supported in part by the European Union Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 604102 (Human Brain Project).
The methods within the package can be cited as:
Tal Galili, Alan O'Callaghan, Jonathan Sidi, Carson Sievert; heatmaply: an R package for creating
interactive cluster heatmaps for online publishing, Bioinformatics, , btx657,
https://doi.org/10.1093/bioinformatics/btx657
A BibTeX entry for LaTeX users is
@Article{,
author = {{Galili} and {Tal} and {O'Callaghan} and {Alan} and {Sidi} and {Jonathan} and {Sievert} and {Carson}},
title = {heatmaply: an R package for creating interactive cluster heatmaps for online publishing},
journal = {Bioinformatics},
year = {2017},
doi = {10.1093/bioinformatics/btx657},
url = {http://dx.doi.org/10.1093/bioinformatics/btx657},
eprint = {https://academic.oup.com/bioinformatics/article-pdf/doi/10.1093/bioinformatics/btx657/21358327/btx657.pdf},
}
This free open-source software implements academic research by the authors and co-workers. If you use it, please support the project by citing the appropriate journal articles.
You are welcome to:
plotly::orca
for saving to file, rather than plotly::export
node_size_mat
argument.custom_hovertext
is not a matrix - it is turned into a matrix (important if inserting a data.frame). Fix issue #151custom_hovertext
argument, adding custom hovertext optionlabel_format_fun
argument, which formats text before adding to
hovertextnode_type argument, which allows users to plot the heatmap with discs rather than squares. See also the
point_size_mat` argument.point_size_mat
argument, which is mapped to point size when
node_type="scatter"
. Also adds point_size_name
argument, which is the
name of this parameter in the heatmap hovertext.distfun="pearson"
, distfun="spearman"
or distfun="kendall"
.
This corresponds to the use of distfun=function(x) as.dist(1 - cor(x)))
.heatmaply
showticklabels
now removes the ticks as
well as the tick labels.cellnote_size
argument, controlling the font size of the cellnote.ggplot_heatmap
side_color_layers
argument, which allows the user to pass in ggplot functions which will be
added to the side color plots.row_side_palette
and col_side_palette
can now be named vectors of
colors.plot_method = "plotly"
, including improved positioning of legends.plot_method = "plotly"
heatmaply.heatmapr()
previously ignored row_side_colors
and col_side_colors
when passed to heatmapr()
(issue #94)cellnote_textposition
argument, which controls the justification of cellnote within a cell.
See the plotly documentation for more details.cellnote
would previously not work with character matrices. This is now fixed.heatmaply
This release adds unit testing and code coverage to the heatmaply package. Users should not be affected, but this will hopefully accelerate development and reduce the occurrence of bugs.
heatmaply
-
subplot_widths
and subplot_heights
arguments for user customisation.plot_method
argument ("plotly" or "ggplot") which controls the underlying
plot method used for dendrograms and the main heatmap.
Currently there is some disparity between the features
available in both methods but it is hoped this can be addressed.
plotly will likely give higher performance for large matrices.plot_method = "plotly". This functionality should also be added to the function when
plot_method = "ggplot"`, once changes are made to the plotly R package.colorbar_len
argument, which controls the fraction of the total height
which the colorbar/color legend will take up.colorbar_xanchor
, colorbar_yanchor
arguments which control
the anchoring points of the colorbar, relative to which the x and y position
is applied ("left", "middle" and "right" for colorbar_xanchor
,
and "top", "middle" or "bottom" for colorbar_yanchor
).plot_method = "plotly"
long_data
argumnet, which allows the user to use data in "long"
format (eg, http://www.theanalysisfactor.com/wide-and-long-data/).label_names
argument, which allows the user to specify names to
replace "row" and "column" as the names of the mouseover co-ordinates.draw_cellnote
argument.
Cellnote color can be controlled by the cellnote_color
argument.
It is hoped that with future versions of plotly, an outline can be added,
in order to make text readable on any background.fontsize_row
and fontsize_col
arguments to heatmaply,
which control font size for row and column labels. cexRow
and cexCol
are
aliases (in order to keep compatability with gplots::heatmap.2).grid_gap
argument. Default is 0, higher numbers influence the gap between cells,
helping the user to identify distinct values/cells within the matrix.heatmapr
is.plotly
- new function to check if an object is of class plotly or not.heatmaply
cexRow
and cexCol
arguments, which were previously non-functional.row_side_colors
, making heatmaply reasonably robust to heterogeneous data.frames.
* main - a new parameter for setting the title of the plot.
* the margins parameter now accepts 4 elements (previously it was only 2), for bottom, left, top (relevant for the plot's title) and right margins.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.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
write example for using seriation+dendextend for heatmaps.
Show the following example for using seriation:
require(seriation) require(dendextend)
d <- dist(USArrests[1:15,]) dend <- as.dendrogram(hclust(d, method = "ave")) par(mfrow = c(1,2)) plot(dend, main = "default")
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 :)