sclee1
sclee1

Reputation: 1281

How to adjust the color range in heatmap.2

I am trying to plot the heatmap using the R language.

After plotting the heatmap graph, I found that the my heatmap was not appropriate for the interpretation because the range of the color key was not well adjusted.

As you can see below, the color key range was very long compared to my data's distributions.(they are between zero to four). Therefore, all the colors in the heatmap were green.

enter image description here

How to solve this problems?

Below are my codes. (I tried to search the solutions, but I failed to find appropriate thread for my case.)

library(gplots)
matrix <- as.matrix(read.delim("bladder",header=FALSE))
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x, method="euclidean")
cl.col <- hclustfunc(distfunc(t(matrix)))
gr.col <- cutree(cl.col, 4)
heatmap.2(as.matrix(matrix),col=greenred(75),dendrogram=c("col"),trace="none",Rowv=FALSE,margins = c(8,16),cexRow=0.60,cexCol=0.8)

Upvotes: 1

Views: 6271

Answers (1)

Hack-R
Hack-R

Reputation: 23231

Make sure you set n to the correct length in the following example:

my_palette <- colorRampPalette(c("red", "blue", "green"))(n = 100)

heatmap.2(as.matrix(matrix), col=my_palette, 
    breaks=colors, density.info="none", trace="none", 
        dendrogram=c("row"), symm=F,symkey=F,symbreaks=T, scale="none")

Upvotes: 4

Related Questions