使用 pheatmap 为热图制作连续颜色图表

发布于 2025-01-11 00:34:01 字数 349 浏览 2 评论 0原文

我正在研究如何使用 pheatmap 包并制作连续的颜色编码热图。

我想为我的地图使用红、白、蓝三种颜色,其中白色 = 0,蓝色代表负数,红色代表正数。我希望它是连续的,而不是任何 0 = 白色,正值是红色,但更多的是从纯红色到浅色的过渡,直到白色。

我在文档中找不到它,所以也许是我对如何使其工作缺乏了解。

这是我目前的代码。

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = c("blue", "white", "red"),
  angle_col = 90)

谢谢你!

I'm looking to figure out how to use the pheatmap package and to make a continuous color coded heatmap.

I would like to use three colors, red, white and blue to for my map, where white = 0, blue is for negative numbers, and red for positive. I want it such that it would be continuous, rather than anything being 0 = white, and positive being red, but more of a transition from a solid red to lighter fades until white.

I couldnt find it in the documentation, so perhaps it is my lack of understanding on how to get it to work.

Here is my code currently.

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = c("blue", "white", "red"),
  angle_col = 90)

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分分钟 2025-01-18 00:34:02

您可以使用 colorRampPalette 提供一个长的过渡颜色向量:

set.seed(1)
heatmap_matrix <- matrix(rnorm(400), nrow = 20)

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = colorRampPalette(c("blue", "white", "red"))(100),
  angle_col = 90)

在此处输入图像描述

You could just supply a long vector of transitioning colours using colorRampPalette:

set.seed(1)
heatmap_matrix <- matrix(rnorm(400), nrow = 20)

pheatmap(heatmap_matrix,
  cluster_rows = T,
  cluster_cols = T,
  color = colorRampPalette(c("blue", "white", "red"))(100),
  angle_col = 90)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文