1

Hi there stackoverflow community!

I am a graduate student inquiring for some consultation on an aethetics R problem I am encountering.

The data I am working with is in the form of a VERY large matrix (49x51).

My problem is that my data ranges from very small to very large, with the bulk of my data falling within the "very large" end of the spectrum, so unless I convert my data to log10, the heatmap is rather boring and almost entirely the same color.

The spectrum of my data is totally within the range I am expecting, but I am hoping to display it in a more aesthetic way.

Proposed solution: I think I need to bin my data in a non-uniform way. If you look at the attached image, you will see that their heatmap looks nice and the color key shows the heat spectrum in a non-fixed bin format. I would like to do something like that, however, I am not sure how to declare cutoffs for each bin. I would ideally like to declare the cutoffs.

For example, bin 1 (0-1), bin 2 (2-50), bin 3 (51-5000). As you can see, my bins would not be fixed in equal increments.

I have been using heatmap.2 for this. Thanks so much in advance!

heatmap with color legend in non-uniform bins:

Djib2011
  • 6,874
  • 5
  • 36
  • 41
  • 1
    Possible duplicate of [How to assign your color scale on raw data in heatmap.2()](https://stackoverflow.com/questions/20535635/how-to-assign-your-color-scale-on-raw-data-in-heatmap-2) – S Rivero Aug 27 '18 at 21:01
  • Welcome to StackOverflow! You've done a good job explaining your question, but in the future, please provide a [minimal reproducible sample](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of your data. Your idea of a `log10` transformation is solid, but you could also use something like `dplyr`'s `mutate` function to create a new column based on your custom ranges – Punintended Aug 27 '18 at 21:01
  • Thanks for the input! I will tinker with what S Rivero mentioned. Also, so sorry for not providing enough information for a perfect picture of what I am trying to do. I think I will first look at the distribution of data to first construct the bins. After a quick glace of S Rivero's link, I think my answer might by within there, but I will be sure to follow up with you both. Thanks for the prompt replies! – Peter Stokes Aug 27 '18 at 21:15
  • Hey guys. I did some research into the issue I am having and it turns out that I should be normalizing my matrix. I think this would alleviate much of the coloration issues I have been encountering. I will keep you posted. Thank you both for your help :) – Peter Stokes Aug 27 '18 at 23:50

1 Answers1

0

Hey @Punintended and @S Rivero,

I think I have reached the point that my heatmap will only improve marginally. Both of you contributed deeply to this success, so thanks! First, to condense the matrix values as much as possible, I normalized by column. I was then able to assign gradients. This turned out much better than I had hoped. As you can see, most of my data is clustered (check out the density in the key) at very low values, this is okay though, for I am interested in the higher values. I had to use custom color gradients to account for possible instances of colorblind attendees that might look at my poster. Anyways, if you guys have comments or recommendations, they will be much appreciated :). Again, thanks a bunch!

enter image description here