使用绝对颜色映射进行热图
我正在尝试创建一个热图,其中细胞的颜色与网格中的其他值不相关,而是与绝对值相关(有点像Excel中的单元格格式,例如,绿色的值在0.20至0.25之间。 )。我一直在玩R软件包超热
,但我仍然不清楚如何提供这样的映射。关于如何完成的任何建议?最好使用过热,但可以提示如何通过其他软件包进行操作。
更新: 例如,使用MTCARS数据集,我们
superheat(mtcars,
X.text = as.matrix(mtcars),
legend.breaks = c(min(mtcars), 0, max(mtcars)))
在数据框中添加了一个新行,我们在原始行中获得了完全相同的值的不同颜色:
mtcars.new <- rbind(mtcars,
extrarow = c(-100, 6, 20, 10, 6, 2, 10, 1, 1, 6, 6))
superheat(mtcars.new,
X.text = as.matrix(mtcars.new),
legend.breaks = c(min(mtcars.new), 0, max(mtcars.new)))
我想拥有的是,颜色不取决于所示的值在数据框中,当为不同的数据集创建地图时,可以将它们直接相互比较。
I am trying to create a heat map where the colors of the cells are not relative to the other values in the grid, but are linked to absolute values (a bit like the cell formatting in excel, e.g., green for values between 0.20 and 0.25). I have been playing around with the R package superheat
but it is still unclear to me how to provide such a mapping. Any recommendations on how this can be done? Preferably using superheat but hints on how to do it via other packages are fine as well.
UPDATE:
For instance, using the mtcars dataset, we get
superheat(mtcars,
X.text = as.matrix(mtcars),
legend.breaks = c(min(mtcars), 0, max(mtcars)))
Adding a new row to the dataframe, we get different colors for the exact same values in the original rows:
mtcars.new <- rbind(mtcars,
extrarow = c(-100, 6, 20, 10, 6, 2, 10, 1, 1, 6, 6))
superheat(mtcars.new,
X.text = as.matrix(mtcars.new),
legend.breaks = c(min(mtcars.new), 0, max(mtcars.new)))
What I would like to have, is that the colors do not depend on the values present in the dataframe, such that when maps are created for different datasets, they can be directly compared to each other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个示例,说明如果您创建一个“ grpcolor”变量,取决于您的变量值。然后,您可以使用此变量值匹配GGPLOT的颜色。 (如果需要,请肯定地更改因素水平)
Here is an example on how you could do if you create a "grpColor" variable depending on your variable value. You could then match colors from ggplot with this variable value. (do not hesite to change factors levels if needed)