Question: How to reduce the length (size) of the dengrogram in heatmap.2
gravatar for BIOAWY
7 weeks ago by
BIOAWY20 wrote:

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", = "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 • 187 views
ADD COMMENTlink modified 7 weeks ago by Kevin Blighe22k • written 7 weeks ago by BIOAWY20
gravatar for Kevin Blighe
7 weeks ago by
Kevin Blighe22k
University College London Cancer Institute
Kevin Blighe22k wrote:

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


ADD COMMENTlink written 7 weeks ago by Kevin Blighe22k

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 REPLYlink written 7 weeks ago by BIOAWY20

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)

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

#Skinny heatmap
pdf("Heatmap.pdf", width=4, height=9)
ADD REPLYlink modified 7 weeks ago • written 7 weeks ago by Kevin Blighe22k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1574 users visited in the last hour