rlbarter / superheat

An r package for generating beautiful and customizable heatmaps
https://rlbarter.github.io/superheat/
238 stars 29 forks source link

problem with legend and colors when using heat.pal, heat.lim and heat.pal.values #3

Closed VGalata closed 7 years ago

VGalata commented 7 years ago

Hi,

I have a problem with superheat when using a custom color palette: I want to define custom colors and transition values but the result is not always as expected. I tried different calls:

Basic call:

superheat(
    X=plot_data$values,
    pretty.order.rows=FALSE, pretty.order.cols=FALSE,
    row.dendrogram=FALSE, col.dendrogram=FALSE,
    smooth.heat=FALSE, scale=FALSE,
    grid.hline.size=0.3, grid.vline.size=0.3, grid.hline.col='white', grid.vline.col='white',
    bottom.label="none"
)
  1. Using heat.pal=colorRampPalette(c("#009900", "#ffcc00"))(6)
    • The color in the legend for the smallest values is not correct, it is not the green defined as the first color in heat.pal and is also different from the color actually used in the heatmap
  2. Using heat.pal=colorRampPalette(c("#009900", "#ffcc00"))(6) and heat.lim=c(0,512)
    • Looks better but it was forced by decreasing the minimal color value below the actual minimum
  3. Using heat.pal=colorRampPalette(c("#009900", "#ffcc00"))(6), heat.pal.values=plot_data$summary with and without heat.lim=c(0.008,512) or heat.lim=c(0,512)
    • The color assignment is completely wrong - only green shades are used and some cells are gray, legend is also wrong
  4. Using heat.pal=colorRampPalette(c("#009900", "#ffcc00"))(6) and heat.lim=c(0.008,512)
    • Coloring seems to be correct but legend is as in the first case, i.e. wrong color for the smallest value

Screenshots are below. Used version: 0.1.0

Thank you in advance!

Screenshots (same order as the listed superheat calls): superheat_01 superheat_02 superheat_03 superheat_04

rlbarter commented 7 years ago

Hi!

So the default location for the color transitions is at the respective quantiles your data - e.g. if you have 6 colors, the color transitions will be at the 0th, 20th, 40th, 60th, 80th and 100th quantiles, where the 0th quantile corresponds to the minimum value and the 100th quantile corresponds to the maximum value.

These transition positions work nicely for highlighting the difference between relative high and low values. Your data seems to be quite skewed, hence why the transitions happen very close to the minimum (the 20th, 40th, 60th quantiles etc are very close to the minimum value).

The heat.lim argument specifically restricts the legend itself rather than the colors appearing in the heatmap (I will make this clearer in the documentation).

I suspect that colors in the original legend are correct, it's just that the transitions are happening to close to the minimum value that the dark green is only for such a small range of values.

If you plot a histogram of your data, you will probably see a large number of very small values and very few large values...

Let me know if this is helpful or if I've misunderstood the issue and I can try to help further :)

VGalata commented 7 years ago

Hi!

I see now that my problem was that I misunderstood the description of the heat.pal argument. Thank you very much for your help!