Heatmap





A heatmap is a graphical representation of data where the individual values contained in a matrix are represented as colors. This page displays many examples built with R, both static and interactive.

Using the heatmap() function

The heatmap() function is natively provided in R. It produces high quality matrix and offers statistical tools to normalize input data, run clustering algorithm and visualize the result with dendrograms. It is one of the very rare case where I prefer base R to ggplot2.





Using geom_tile() from ggplot2

ggplot2 also allows to build heatmaps thanks to geom_tile(). However, I personally prefer the heatmap() function above since only it offers option for normalization, clustering and Dendrogram.





Interactive heatmaps from R

Three options exist to build an interactive heatmap from R:

  • plotly: as described above, plotly allows to turn any heatmap made with ggplot2 interactive.

  • d3heatmap: a package that uses the same syntax as the base R heatmap() function to make interactive version.

  • heatmaply: the most flexible option, allowing many different kind of customization. See the code of the chart beside here.
See code Heatmap section




Heatmap for time series

Heatmaps can be a very good alternative to visualize time series, especially when the time frame you study is repeating, like weeks. Here is a customized example, but visit the time series section for more.

Code Time series section
heatmap for time series in R




Using the levelplot() function of lattice

Related chart types


Scatter
Heatmap
Correlogram
Bubble
Connected scatter
Density 2d