Saturday, February 9, 2013

Customerize a heatmap with clustering panel in R

pdf("_20130209.average.hclust.2.coat.pdf", height=5, width=5);
 mymethod = "average";
 hd =  hclust( dist(ctb2), mymethod);
 coat.cat = cutree(hd, numclus )
 #col.palette = c("red","brown","blue","green");
 col.palette = c("blue","red"); #2013 Feb 9 change
 coat.color = col.palette[coat.cat]

 hcol =  hclust(dist( t(ctb2)), method=mymethod )
 #hcol =  as.dendrogram( hclust(dist( t(ctb2)), method=mymethod ) )

 #library(RColorBrewer);
 #hmcol = colorRampPalette(brewer.pal(5,"RdBu"))(16);

 #using the default heatmap function
 heatmap( ctb2, col=c("red","blue"), scale="none", margins = c(5,22),
 #Colv = NA,  ## no dedrogram
 #Colv = FALSE, ## use the input column order, 
 #Colv = as.dendrogram( hclust(dist( t(ctb2)), method=mymethod ) ),
 RowSideColors=coat.color, # ColSideColors = spec.colors, #20130209
 hclustfun = function(c) hclust( c, method=mymethod),
 cexRow=0.4, cexCol=0.6 );

dev.off();

No comments:

Post a Comment