I have the following code:
library(gplots)
library(RColorBrewer);
setwd("~/Desktop")
mydata <- mtcars
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x,method="euclidean")
d <- distfunc(mydata)
fit <- hclustfunc(d)
clusters <- cutree(fit, h=100)
nofclust.height <- length(unique(as.vector(clusters)));
# Colorings
hmcols <- rev(redgreen(2750))
selcol <- colorRampPalette(brewer.pal(12,"Set3"))
selcol2 <- colorRampPalette(brewer.pal(9,"Set1"))
clustcol.height = selcol2(nofclust.height);
heatmap.2(as.matrix(mydata),
trace='none',
dendrogram='both',
key=F,
Colv=T,
scale='row',
hclust=hclustfunc, distfun=distfunc, col=hmcols,
symbreak=T,
margins=c(7,10), keysize=0.1,
lwid=c(5,0.5,3), lhei=c(0.05,0.5),
lmat=rbind(c(5,0,4),c(3,1,2)),
labRow=rownames(mydata),
#ColSideColors=clustcol.height[clusters], # This line doesn't work
RowSideColors=clustcol.height[clusters])
Which produce the following figure:
What I want to do is to perform clustering on both row and column and show clustering bars (RowSideColors and ColSideColors) next to dendogram. How can I achieve that?
At the moment I only succeed in showing RowSideColors
but not the ColSideColors
one.