How to reduce the length (size) of the dengrogram in heatmap.2
1
1
Entering edit mode
3.0 years ago
Wox ▴ 460

This is the code I've used to build by Heatmap with dendrogram

heatmap.2(as.matrix(SI_Ratios), scale = "none", col = bluered(100),
trace = "none", density.info = "none", cexRow=0.5, cexCol=0.75, margins = c(5,20),
key.xlab = "Ln(Peak Area / T0)")


How can I reduce the length of the dendrogram? Also How to increase the font size of the Color Key description?

R gene • 8.0k views
ADD COMMENT
1
Entering edit mode
3.0 years ago

For modifying the font size of the colour key, just use the key.lab parameter (as I do below).

For changing the 'length' of the dendrogram, you have to realise that the dendrogram heights are representative of the distances between your samples and are measured on the scale that you used during the creation of the distance matrix, usually Euclidean distance. Euclidean distances can be large, depending on your data-type, even into the 100s.

You can play around with the margins in order to 'squeeze' the dendrgrams - you can do this via par(oma). Here, I have modified the left margin with par(oma=c(1,15,1,1)):

data <- replicate(20, rnorm(50))
rownames(data) <- paste("Gene", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))
par(oma=c(1,15,1,1)); heatmap.2(data, key=TRUE, keysize=1.5, key.xlab="X-axis", key.ylab="", key.title="", key.par=list(mar=c(4,0,1,2), cex=1.0, cex.lab=2.0, cex.axis=2.0), margins=c(5,5))


If you wanted a distance metric that is measured on a smaller range, you could do correlation distance by adding distfun=function(x) as.dist(1-cor(t(x))) to the heatmap.2 function, as I do here: A: Hierarchical Clustering in single-channel agilent microarray experiment

Kevin

ADD COMMENT
0
Entering edit mode

Thanks, Kevin,

This works for me. However, I can not zoom the Heatmap and its blurred. How can I save this to a PNG with good resolution

ADD REPLY
2
Entering edit mode

Don't use PNG if you want a very clear image. PNG, TIFF, BMP, etc., are pixel-based. If you instead use a vector-based graphics format, then you would get publication-ready figures. You can then use the width and height parameters in order to modify the size (inches) of the output.

#Default size
pdf("Heatmap.pdf", width=7, height=7)
...
dev,.off()

#Wide heatmap
pdf("Heatmap.pdf", width=9, height=4)
...
dev,.off()

#Skinny heatmap
pdf("Heatmap.pdf", width=4, height=9)
...
dev,.off()

ADD REPLY

Login before adding your answer.

Traffic: 1375 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