Question: How To Generate A Smaller, Simpler Heatmap Similar To A Tile?
3
k.nirmalraman1.0k wrote:

I am trying to make a heatmap and the was able to achieve the one I wanted. However, I have a feeling it looks clumpsy. `Y` is a 4 column matrix with expression values

``````y<-ave_scaledCounts[Gene_Markers,]
hr <- hclust(as.dist(1-cor(t(y), method="pearson")), method="centroid");
hc <- hclust(as.dist(1-cor(y, method="spearman")), method="centroid")
# Cuts the tree and creates color vector for clusters.
mycl <- cutree(hr,k=4, h=max(hr\$height)/2);
mycolhc <- rainbow(length(unique(mycl)), start=0.1, end=0.9); mycolhc <- mycolhc[as.vector(mycl)]
myheatcol <- bluered(75)
pdf("Hierarchial_Clustering/Final_HeatMap Hierarchial clustering.pdf",width=9,height=7)
heatmap.2(y, Rowv=as.dendrogram(hr), Colv=as.dendrogram(hc), col=myheatcol, scale="row", density.info="none", trace="none",
+    RowSideColors= mycolhc,margins=c(10,10),keep.dendro=FALSE)
dev.off()
``````

. I would like the heatmap in itself to be smaller in area... preferable like a tile!! The dendograms are not neccessary and the color key could be even thinner! ANy help would be great! Thanks!

EDIT: Would it just be possible to make a better heatmap if I just have the clusters in order already?? May be `ggplot2` package heatmap • 4.3k views
modified 7.4 years ago by Alex Reynolds31k • written 7.4 years ago by k.nirmalraman1.0k

clearly this scale is not appropriate for correlations. wouldn't you normally calculate some kind of distance value?

I thought I was doing it here `as.dist(1-cor(t(y)`

Do you mean the color scale is not appropriate? If you dont mind could you expand a bit more??

have you tried just euclidean distances on the raw data?

``````dists<-dist(t(y))
heatmap( as.matrix( dists ))
``````

This just made a huge square with same color, I mean the clusters cannot be seen. I added `col=myheatcol"`

1
Alex Reynolds31k wrote:

Perhaps you could try `myheatcol <- colorpanel(3, "#0000ff", "#ffffff", "#ff0000")` or `myheatcol <- bluered(3)` to "force" each cell to fall into one of three colors.

Even narrower would be `myheatcol <- colorpanel(2, "#0000ff", "#ff0000")` or `myheatcol <- bluered(2)`. In that case, a cell is either blue or red.

This probably won't work too well for smaller clusters, but it should work okay for larger ones, I'd think.

If you want to keep a blue-to-white gradient for values from -1.5 to 0 and have all z-scores greater than 0 be painted one shade of red, you could construct a color palette vector like so:

``````> myheatcol.bluewhite <- colorpanel(128, "#0000ff", "#ffffff")
> myheatcol.red <- rep("#0000ff", 127)
> myheatcol <- c(myheatcol.bluewhite, myheatcol.red)
``````

Thank you!! Actually, the color gradient is just fine.. I would however like to know how can I

1. reduce the size of the heatmap (width of the heatmap matrix)
2. remove the dendogram without changing the order (the data can also be already pre-ordered if required... however, HC does a )good job too
0
Fwip490 wrote:

Have you tried `heatmap.2( ..., dendrogram = "none" ... )` to turn off the dendrogram? Remember to check `? heatmap.2` for usage info.