Question: how to give limitation in heatmap3
0
gravatar for miniymay101
16 months ago by
miniymay1010 wrote:

Hi,

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 • 863 views
ADD COMMENTlink modified 13 months ago by zhaoshilin0 • written 16 months ago by miniymay1010
0
gravatar for tiago211287
16 months ago by
tiago2112871.1k
USA
tiago2112871.1k 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 16 months ago • written 16 months ago by tiago2112871.1k
0
gravatar for zhaoshilin
13 months ago by
zhaoshilin0
zhaoshilin0 wrote:

Hello,

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

testData<-matrix(1:12,ncol=3)
heatmap3(testData,scale="none",Rowv=NA,Colv=NA,col=colorRampPalette(c('chartreuse4','white','firebrick'))(1024))

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

col<-colByValue(testData,col=colorRampPalette(c('chartreuse4','white','firebrick'))(1024),range=c(1,5))
heatmap3(testData,scale="none",Rowv=NA,Colv=NA,col=col)

Or

heatmap3(testData,scale="none",Rowv=NA,Colv=NA,col=as.vector(col)[order(as.vector(testData))])
ADD COMMENTlink written 13 months ago by zhaoshilin0
Please log in to add an answer.

Help
Access

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