3

I have a 2000$\times$2000 matrix of values. Over half of the values are 0, and for those non-zeros, most of them are less than 10, but the maximum value is 140.

So when I do a heatmap, it looks like a single color with couple of spots in it.

What should I do to rescale them so that it looks prettier in a heatmap?

I tried multiplying by 10, but it doesn't work very well.

Glen_b
  • 257,508
  • 32
  • 553
  • 939
lxcfuji
  • 31
  • 3
  • It might look better (more informative) if you used colors based on something more like the square root of the values you have. You'd have to clearly indicate that the scaling wasn't linear though. – Glen_b Dec 12 '14 at 02:03

1 Answers1

1

Since the distribution of your values is clearly right skewed, I would suggest log-transforming the data and then scaling correspondingly for plotting (obviously, you need to convert zeroes to non-zeroes prior to the transformation, for example by adding a small value or similar technique). Square root transformation, suggested by @Glen_b would work, too, but I believe that logarithm is a stronger transformation, if you need that. Depending on your particular data and visualization needs, you can choose the optimal solution between those. Other transformations are also available, see more information here: http://fmwww.bc.edu/repec/bocode/t/transint.html.

If you use R, ggplot2 is nice - I've seen some ggplot2-based heatmap implementations. For example, this blog post and comments partially address the topic, including the scaling aspect: http://learnr.wordpress.com/2010/01/26/ggplot2-quick-heatmap-plotting. If you want additional visualization emphasis on categories, check this nice follow-up Q&A on StackOverflow: https://stackoverflow.com/q/13016022/2872891.

Aleksandr Blekh
  • 7,867
  • 2
  • 27
  • 93
  • I'm looking at it now! do you know how to remove all those grey boarder from the initial heatmap? – lxcfuji Dec 12 '14 at 03:08
  • @lxcfuji: Just don't use "grey"/default theme and/or use different theme - "blank" or "black and white" or other. See http://docs.ggplot2.org/0.9.2.1/theme.html and http://sape.inf.usi.ch/quick-reference/ggplot2/themes. – Aleksandr Blekh Dec 12 '14 at 04:07