本文介绍了在R中的自定义热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建自定义热图,如附图所示。它不同于传统的热图,在我想要它使用两个颜色渐变,一个为正值和一个为负值。

I need to create custom heat map as illustrated in the attached figure. It is different from a conventional heat map in the sense that I want it to use two color gradients, one for positive values and one for negative values.

如附图所示,我想要一种颜色来描绘正值(或者理想地高于某个阈值)的值的强度,并且另一种颜色描绘值的强度(或者,低于阈值)。

As shown in the attached figure, I would like one color to depict the intensity of the values that are positive (or ideally above a certain threshold) and another color to depict the intensity of the values that are negative (alternatively, below the threshold).

一点背景:我有一个二进制选择集,一个选项是优先于某一范围的数据,而另一个选择优先于剩余的数据。我想提供一个视觉帮助,将描述哪个选项/选择更好的不同的数据组合,但我想要视觉帮助还提供一个选项已经超过了另一个实例的bettern的规模。所以颜色会告诉选择哪个选项,而颜色的强度告诉多少更好的选项相比其他。

A little background: I have a binary choice set, one option is to be preferred for a certain range of data while the other is preferred for the remaining data. I want to provide a visual aid that will depict which option/choice is better for the different combinations of data but I want the visual aid to also provide the scale of "betterness" that one option has over the other for that instance. So the color would tell which option to pick while the intensity of the color with tell how much better is that option compared to the other.

推荐答案

这里是使用 ggplot2 的示例:

# sample data
df <- data.frame(expand.grid(x = 1:4, y = 1:4), v = runif(16, -10, 10))

# plot
ggplot(df, aes(x, y, fill = v, label = sprintf("%.1f", v))) +
  geom_tile() + geom_text() +
  scale_fill_gradient2(low = "blue", high = "red")

>

这篇关于在R中的自定义热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 14:24