如何更改heatmap.2中的颜色键值? [英] How to change the color key value in heatmap.2?
问题描述
如上面的屏幕截图所示,我在这里使用了功能heatmap.2()
.
As the above screenshot showed, I used the function heatmap.2()
here.
如何在颜色编码栏中将"值"更改为任何其他名称?
how can I change 'Value' in the color coded bar to any other name?
一个人只能使用gplots包中的数据:
One can just use the data from gplots package:
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)
非常感谢:-)
推荐答案
它是硬编码的.您将需要在代码中进行更改.大约在绘制键的部分的中间,线是:
It's hard-coded. You will need to change it in the code. It appears about midway down the section that draws the key and the line is:
else mtext(side = 1, "Value", line = 2)
这是heatmap.2代码的一部分,它创建密钥(至少直到出现"Value"一词的地方):
This is the section of the heatmap.2 code that creates the key (at least up to the point where the word "Value" appears) :
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
您应该键入heatmap.2
,然后将源代码复制到编辑器,然后使用搜索功能查找值".将值"更改为其他内容(用引号引起来),然后键入heatmap.2 <-
并粘贴代码并按回车键. (除非您保存此设置,否则它将仅在会话继续进行的情况下持续存在.)
You should type heatmap.2
, then copy the source code to an editor and then use the search function to find "Value". Change "Value" to something else (in quotes) and then type heatmap.2 <-
and paste in the code and hit return. (Unless you save this it will only persist as long as the session continues.)
这篇关于如何更改heatmap.2中的颜色键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!