R: heatmap.2 change color key

前端 未结 1 1636
死守一世寂寞
死守一世寂寞 2021-02-06 10:28

I have a question about the package gplots. I want to use the function heatmap.2 and therefore I want to change my symmetric point in color key from 0

1条回答
  •  囚心锁ツ
    2021-02-06 11:00

    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.

    0 讨论(0)
提交回复
热议问题