R:heatmap.2更改颜色键 [英] R: heatmap.2 change color key
问题描述
我有关于 gplots
的问题。我想使用函数 heatmap.2
,因此我想将颜色键中的对称点从0更改为1.通常当 symkey = TRUE
,并使用 col = redgreen()
创建一个彩色条,其中的颜色管理如下:
red = -2至-0.5
black = -0.5至0.5
green = 0.5至2
现在我要创建一个这样的颜色条:
code> red = -1至0.8
black = 0.8至1.2
green = 1.2至3
这样的东西可能吗?
谢谢!
解决方案如果您看一下 heatmap.2帮助文件,它看起来像你想要的
断言
参数。从帮助文件中:
break
用于将x分组为颜色的分裂点或者要使用的整数个断点,在这种情况下,断点将在min(x)和max(x)之间等间隔
因此,您可以使用
break
指定每种颜色的截止点。例如:库(gplots)
#构成一堆从-1开始的随机数据, (样本(seq(-1,3,by = .1),100,replace = TRUE),...,9, ncol = 10)
#plot。我们想要-1到0.8是红色,0.8到1.2是黑色,1.2到3是绿色。
heatmap.2(x,col = redgreen,breaks = c(-1,0.8,1.2,3))
关键的是
breaks = c(-1,0.8,1.2,3)
是你的临界值。I have a question about the package
gplots
. I want to use the functionheatmap.2
and therefore I want to change my symmetric point in color key from 0 to 1. Normally whensymkey=TRUE
and you use thecol=redgreen()
, a colorbar is created where the colors are managed like this:red = -2 to -0.5 black=-0.5 to 0.5 green= 0.5 to 2
Now i want to create a colorbar like this:
red= -1 to 0.8 black= 0.8 to 1.2 green= 1.2 to 3
Is something like this possible?
Thank you!
解决方案If you look at the heatmap.2 help file, it looks like you want the
breaks
argument. From the help file:
breaks
(optional) Either a numeric vector indicating the splitting points for binning x into colors, or a integer number of break points to be used, in which case the break points will be spaced equally between min(x) and max(x)So, you use
breaks
to specify the cutoff points for each colour. e.g.:library(gplots) # make up a bunch of random data from -1, -.9, -.8, ..., 2.9, 3 # 10x10 x = matrix(sample(seq(-1,3,by=.1),100,replace=TRUE),ncol=10) # plot. We want -1 to 0.8 being red, 0.8 to 1.2 being black, 1.2 to 3 being green. heatmap.2(x, col=redgreen, breaks=c(-1,0.8,1.2,3))
The crucial bit is the
breaks=c(-1,0.8,1.2,3)
being your cutoffs.这篇关于R:heatmap.2更改颜色键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!