<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/superheat-supercharged-heatmaps-for-r/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/02/superheat-supercharged-heatmaps-for-r.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>The <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2010/01/how-to-make-a-heat-map-in-r.html">heatmap</a> is a useful graphical tool in any data scientist's arsenal. It's a useful way of representing data that naturally aligns to numeric data in a 2-dimensional grid, where the value of each cell in the grid is represented by a color. It's a natural fit for data that's in a grid already (say, a <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2014/08/quantitative-finance-applications-in-r-8.html">correlation matrix</a>). But it's also useful for data that can be arranged in a grid, like <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2016/11/divvy-chicago.html">quantities in a calendar</a>, as a way of <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2015/04/r-for-more-powerful-clustering.html">comparing clusters</a>, or simply as a <a target="_blank" rel="nofollow" href="http://blog.revolutionanalytics.com/2016/09/choose-a-good-heatmap-color-scale-with-viridis.html">combination of two categorical or discrete variables</a>.</p>
<p>The base R <a target="_blank" rel="nofollow" href="https://www.rdocumentation.org/packages/stats/versions/3.3.1/topics/heatmap">heatmap</a> function does a good job of generating basic heatmaps (this <a target="_blank" rel="nofollow" href="http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/">FlowingData tutorial</a> showcases its capabilities), but if you want to put anything on the margins besides labels you're going to need something more powerful. The <a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat/index.html">superheat package</a> by Rebecca Barter (currently <a target="_blank" rel="nofollow" href="https://github.com/rlbarter/superheat">available only on GitHub</a>) provides many additional capabilites for basic heatmaps (like ordering the rows/columns, or choosing a color scheme) and also the option to supercharge the heatmap with annotations and additional data visualizations in the margins. Here are a few <a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/">examples</a>: </p>
<p>Add a scatterplot (or boxplot) to the one of the margins (<a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/fMRI/">details and code</a>):</p>
<p><a target="_blank" rel="nofollow" href="http://a2.typepad.com/6a0105360ba1c6970c01bb0974f54a970d-pi"><img title="Scatterplot" alt="Scatterplot" src="http://a2.typepad.com/6a0105360ba1c6970c01bb0974f54a970d-800wi" border="0"></a></p>
<p>Color the labels by another variable (here, Human Development Ranking, also represented as a bar chart — <a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/Organ/">details and code here</a>):</p>
<p><a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/Organ/"><img title="Organs" alt="Organs" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb0974f58e970d-800wi" border="0"></a></p>
<p>Or add dendrograms (perhaps from a clustering process) to the margins (<a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/Word2Vec/">details and code</a>):</p>
<p><a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/Word2Vec/"><img title="Dendrograms" alt="Dendrograms" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb0974f5b8970d-800wi" border="0"></a></p>
<p>While the superheat pacakge uses the ggplot2 package internally, it doesn't itself follow the grammar of graphics paradigm: the function is more like a traditional base R graphics function with a couple of dozen options, and it creates a plot directly rather than returning a ggplot2 object that can be further customized. But as long as the options cover your heatmap needs (and that's likely), you should find it a useful tool next time you need to represent data on a grid.</p>
<p>The superheat package apparently works with any R version after 3.1 (and I can confirm it works on the most recent, R 3.3.2). This <a target="_blank" rel="nofollow" href="https://arxiv.org/pdf/1512.01524v2.pdf">arXiv paper</a> provides some details and several case studies, and you can find <a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat-examples/">more examples here</a>. Check out the <a target="_blank" rel="nofollow" href="https://rlbarter.github.io/superheat/index.html">vignette</a> for detailed usage instructions, and download it from its GitHub repository linked below.</p>
<p>GitHub (rlbarter): <a target="_blank" rel="nofollow" href="https://github.com/rlbarter/superheat">superheat</a></p>
<p> </p>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2017/02/superheat-supercharged-heatmaps-for-r.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/W7C7F1Fdx0w"></a></div>