How to change heatmap.2 color range in R?

前端 未结 4 954
小蘑菇
小蘑菇 2020-12-23 12:21

I\'m using gplot to produce a heatmap showing log2-fold changes of a treatment groups versus paired controls. With the following code:

 heatmap.2(as.matrix(S         


        
4条回答
  •  猫巷女王i
    2020-12-23 13:27

    Here's another option for those not using heatmap.2 (aheatmap is good!)

    Make a sequential vector of 100 values from min to max of your input matrix, find value closest to 0 in that, make two vector of colours to and from desired midpoint, combine and use them:

    breaks <- seq(from=min(range(inputMatrix)), to=max(range(inputMatrix)), length.out=100)
    midpoint <- which.min(abs(breaks - 0))
    rampCol1 <- colorRampPalette(c("forestgreen", "darkgreen", "black"))(midpoint)
    rampCol2 <- colorRampPalette(c("black", "darkred", "red"))(100-(midpoint+1))
    rampCols <- c(rampCol1,rampCol2)
    

提交回复
热议问题