R 中的自定义热图 [英] Custom Heat Map in R

查看:30
本文介绍了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).

一点背景:我有一个二元选择集,一个选项是特定范围的数据的首选,而另一个是剩余数据的首选.我想提供一个视觉辅助工具来描述哪个选项/选择更适合不同的数据组合,但我希望视觉辅助工具还提供一个选项相对于另一个选项的更好"比例.所以颜色会告诉你选择哪个选项,而颜色的强度会告诉你该选项与另一个选项相比有多好.

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 的例子:

here is an example using 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 中的自定义热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆