gpt4 book ai didi

r - 在 R 中为 pheatmap 设置 0 点

转载 作者:行者123 更新时间:2023-12-02 02:56:08 53 4
gpt4 key购买 nike

如何在此热图中将色标上的 0 点设置为白色?它使用 breaks 参数吗?

在以下代码中,白色设置为 3(或刻度附近):

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Name", 1:20, sep = "")
pheatmap(test, color = colorRampPalette(c("yellow", "white", "blue"))(50))

enter image description here

最佳答案

这可以使用breaks来解决。分隔符对应于调色板箱的数字范围。

test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Name", 1:20, sep = "")

paletteLength <- 50
myColor <- colorRampPalette(c("yellow", "white", "blue"))(paletteLength)
# length(breaks) == length(paletteLength) + 1
# use floor and ceiling to deal with even/odd length pallettelengths
myBreaks <- c(seq(min(test), 0, length.out=ceiling(paletteLength/2) + 1),
seq(max(test)/paletteLength, max(test), length.out=floor(paletteLength/2)))

# Plot the heatmap
pheatmap(test, color=myColor, breaks=myBreaks)

要查看这些向量的内容:

> myColor
[1] "#FFFF00" "#FFFF0A" "#FFFF14" "#FFFF1F" "#FFFF29" "#FFFF34" "#FFFF3E" "#FFFF48" "#FFFF53" "#FFFF5D"
[11] "#FFFF68" "#FFFF72" "#FFFF7C" "#FFFF87" "#FFFF91" "#FFFF9C" "#FFFFA6" "#FFFFB0" "#FFFFBB" "#FFFFC5"
[21] "#FFFFD0" "#FFFFDA" "#FFFFE4" "#FFFFEF" "#FFFFF9" "#F9F9FF" "#EFEFFF" "#E4E4FF" "#DADAFF" "#D0D0FF"
[31] "#C5C5FF" "#BBBBFF" "#B0B0FF" "#A6A6FF" "#9C9CFF" "#9191FF" "#8787FF" "#7C7CFF" "#7272FF" "#6868FF"
[41] "#5D5DFF" "#5353FF" "#4848FF" "#3E3EFF" "#3434FF" "#2929FF" "#1F1FFF" "#1414FF" "#0A0AFF" "#0000FF"
> myBreaks
[1] -1.73042462 -1.66120764 -1.59199065 -1.52277367 -1.45355668 -1.38433970 -1.31512271 -1.24590573
[9] -1.17668874 -1.10747176 -1.03825477 -0.96903779 -0.89982080 -0.83060382 -0.76138683 -0.69216985
[17] -0.62295286 -0.55373588 -0.48451889 -0.41530191 -0.34608492 -0.27686794 -0.20765095 -0.13843397
[25] -0.06921698 0.00000000 0.24694000 0.75110917 1.25527833 1.75944750 2.26361667 2.76778583
[33] 3.27195500 3.77612417 4.28029333 4.78446250 5.28863167 5.79280083 6.29697000 6.80113917
[41] 7.30530833 7.80947750 8.31364667 8.81781583 9.32198500 9.82615417 10.33032333 10.83449250
[49] 11.33866167 11.84283083 12.34700000

enter image description here

关于r - 在 R 中为 pheatmap 设置 0 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31677923/

53 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com