Applying A Divergent Color Scale to A Gene Expression Heat Map

[This article was first published on Optinalysis, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Estimated Read Time: Under 5 minutes

This is a quick post about a quick little experiment I tried lately. I saw a recent post about how red and blue color scales on political heat maps can be misleading–primarily because human perception is not very good at discriminating between shades of purple in the presented scenario.

Since gene expression heat maps are virtually a right of passage in bioinformatics, I thought I’d try and rescale the colors on a gene expression heat map to a properly divergent color scale and visualize the results. Results Below:



At the top is a plot (green and blue) generated using the code available on Peter Cock’s website (but modified to only use 10 colors on the scale). Below that is the plot (red and blue) generated with my modified version.

And of course, code for your consumption:

Thanks to Kenneth Moreland’s research on color scales, and José Gama’s implementation in R (now part of Rgnuplot), all it took was a one line modification of Peter’s code to switch to the new divergent color scale!

The new scale does seem to help us visually discriminate between the elements in the “muddy” area of the left plot. However, since the use of the heat map in bioinformatics is more aesthetic than functional, I’m afraid the fruits seem to stop there. Although this is paints a prettier picture, the hierarchical clustering results remain unchanged. Fun to try though! And now we know a divergent color scale function implementation exists in R!

It always takes a while to write a blog post. In return, all I ask is that you share. Also, if you are a Python or R coder and would like to learn to use D3.js, please check out my O’Reilly Media product, D3 and Coffeescript: A Python Programmer’s Introduction to Web Visualizations.

To leave a comment for the author, please follow the link and comment on their blog: Optinalysis. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)