如何更改heatmap.2中的颜色键值?

Mat*_*att 3 r heatmap

在此输入图像描述

如上面的截图所示,我在heatmap.2()这里使用了这个功能.

如何将颜色编码栏中的" " 更改为任何其他名称

可以使用gplots包中的数据:

 library(gplots)

 data(mtcars)

 x  <- as.matrix(mtcars)

 rc <- rainbow(nrow(x), start=0, end=.3)

 cc <- rainbow(ncol(x), start=0, end=.3)

 heatmap.2(x, key=TRUE)
Run Code Online (Sandbox Code Playgroud)

非常感谢 :-)

mil*_*ilo 10

自@BondedDust回答以来,函数heatmap.2可能已经改变,但现在可以通过以下方式轻松更改heatmap.2键标签:

key.xlab="New value"

首先,你的代码来自上面(使用标准颜色):

library(gplots)
data(mtcars)
x  <- as.matrix(mtcars)
heatmap.2(x,key=TRUE)
Run Code Online (Sandbox Code Playgroud)

关键截图之前

现在替换x和y标签:

library(gplots)
data(mtcars)
x  <- as.matrix(mtcars)
heatmap.2(x, key=TRUE , key.xlab="New value", key.ylab="New count")
Run Code Online (Sandbox Code Playgroud)

关键截图后


42-*_*42- 2

它是硬编码的。您需要在代码中更改它。它出现在绘制关键部分的中间位置,该行是:

else mtext(side = 1, "Value", line = 2)
Run Code Online (Sandbox Code Playgroud)

这是 heatmap.2 代码中创建键的部分(至少直到出现“Value”一词的地方):

 if (key) {
        par(mar = c(5, 4, 2, 1), cex = 0.75)
        tmpbreaks <- breaks
        if (symkey) {
            max.raw <- max(abs(c(x, breaks)), na.rm = TRUE)
            min.raw <- -max.raw
            tmpbreaks[1] <- -max(abs(x), na.rm = TRUE)
            tmpbreaks[length(tmpbreaks)] <- max(abs(x), na.rm = TRUE)
        }
        else {
            min.raw <- min(x, na.rm = TRUE)
            max.raw <- max(x, na.rm = TRUE)
        }
        z <- seq(min.raw, max.raw, length = length(col))
        image(z = matrix(z, ncol = 1), col = col, breaks = tmpbreaks, 
            xaxt = "n", yaxt = "n")
        par(usr = c(0, 1, 0, 1))
        lv <- pretty(breaks)
        xv <- scale01(as.numeric(lv), min.raw, max.raw)
        axis(1, at = xv, labels = lv)
        if (scale == "row") 
            mtext(side = 1, "Row Z-Score", line = 2)
        else if (scale == "column") 
            mtext(side = 1, "Column Z-Score", line = 2)
        else mtext(side = 1, "Value", line = 2)
 .... lots more code below
Run Code Online (Sandbox Code Playgroud)

您应该输入heatmap.2,然后将源代码复制到编辑器,然后使用搜索功能查找“Value”。将“值”更改为其他内容(在引号中),然后键入heatmap.2 <-并粘贴代码并按回车键。(除非您保存它,否则它只会在会话继续时持续存在。)