Question: how to give limitation in heatmap3
gravatar for miniymay101
2.3 years ago by
miniymay1010 wrote:


now I am drawing a heatmap using heatmap3 package in R.

I have a question in drawing heatmap.

My read count datas are ranged from about [-8,8], but I want to make the colors presented in [-1,1].

For example, if my read count data is bigger than 1 (e.g. 4), than it should be represented in the color of 1.

I thought I can do this by using "range" options in heamap3, but it doesn't really work...

Is there anyone who can help me to figure out this...?

I would be very grateful.. Thank you!

My code is :

ColSideAnn <- wholeSampleName_with_false

RowSideColors<-colorRampPalette(c("green", "black", "red"))(34)

result<-heatmap3(logCPM_with_immune,ColSideCut=1.2,ColSideAnn=ColSideAnn,ColSideFun=function(x) showAnn(x),RowSideColors=RowSideColors,
                                  col=colorRampPalette(c("green","black", "red"))(1024),RowAxisColors=1,verbose=TRUE,labCol = "", balanceColor = T)

I thought this might work, but it doesn't help :

col <- colByValue(logCPM_with_immune, range = c(-1, 1), col = colorRampPalette(c("green","black", "red"))(1024))

result<-heatmap3(logCPM_with_immune,ColSideCut=1.2,ColSideAnn=ColSideAnn,ColSideFun=function(x) showAnn(x),RowSideColors=RowSideColors,
                 RowAxisColors=1,verbose=TRUE,labCol = "", col=col)
heatmap3 • 1.5k views
ADD COMMENTlink modified 2.2 years ago by zhaoshilin0 • written 2.3 years ago by miniymay1010
gravatar for tiago211287
2.3 years ago by
tiago2112871.2k wrote:

First, nice R package. Second, it should be easier to help you with a sample of your dataset ~10 lines.

I never used heatmap3 but, if you do not need to represent datapoints bigger than 1 or smaller than -1, why not just simply change your values in your dataset to 1 or -1? something like: make backup data

backup.dataset <- dataset

assign 1 to values bigger than 1 or smaller than -1

for ( i in seq(1,ncol)){
      for ( f in seq(1,nrow)){
        if (dataset[f,i] > 1){
          dataset[f,i] <- 1} else{}
        if (dataset[f,i] < -1){
          dataset[f,i] <- -1} else{}

ADD COMMENTlink modified 2.3 years ago • written 2.3 years ago by tiago2112871.2k
gravatar for zhaoshilin
2.2 years ago by
zhaoshilin0 wrote:


Here is my example code to answer your question. Let me know if you have further question on it.


If we only want to show color in 1 to 5 range, for values>5, using 5 color



ADD COMMENTlink written 2.2 years ago by zhaoshilin0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1143 users visited in the last hour