how to give limitation in heatmap3
2
0
Entering edit mode
6.2 years ago

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 • 2.9k views
ADD COMMENT
0
Entering edit mode
6.2 years ago
tiago211287 ★ 1.4k

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 COMMENT
0
Entering edit mode
6.1 years ago
zhaoshilin • 0

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 COMMENT

Login before adding your answer.

Traffic: 2487 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6