############################################################################### ## Heatmap mit farbigen Dendrogrammen ############################################################################### library(hopach) library(RColorBrewer) library(genefilter) data(golub) golub.names <- ifelse(golub.cl, "AML", "ALL") colnames(golub) <- golub.names ## nur zur Demonstration rownames(golub) <- sample(1:4, nrow(golub), replace = TRUE) ## Auswahl mittels t-Test group <- factor(golub.names) f1 <- ttest(group, p = 0.00001) select <- genefilter(golub, f1) golub <- golub[select,] ## Funktion zum Einfaerben und Beschriften von Dendrogrammen colLab <- function(n, mypalette, group){ if(is.leaf(n)){ a <- attributes(n) ind <- which(a$label == levels(group)) attr(n, "nodePar") <- c(a$nodePar, list(lab.col = mypalette[ind], lab.cex = 0.5, pch = "", col = mypalette[ind])) attr(n, "edgePar") <- c(a$edgePar, list(col = mypalette[ind])) } n } hc1 <- hclust(dist(t(golub)), method = "complete") dend1 <- dendrapply(as.dendrogram(hc1), colLab, mypalette = brewer.pal(3, "Set1"), group = group) plot(dend1) hc2 <- hclust(dist(golub), method = "average") dend2 <- dendrapply(as.dendrogram(hc2), colLab, mypalette = brewer.pal(8, "Set2"), group = as.factor(rownames(golub))) plot(dend2) library(gplots) heatmap.2(golub, Colv = dend1, Rowv = dend2, col = rev(colorRampPalette(brewer.pal(10, "RdYlBu"))(128)), trace = "none", tracecol = "black", add.expr = c(mtext(c("AML", "ALL"), at = c(6, 25), line = 0.7, font = 2), mtext(hc2$labels[hc2$order], side = 2, at = 1:nrow(golub), line = 0.7, font = 1, cex = 0.5)), ColSideColors = brewer.pal(3, "Set1")[factor(hc1$labels)], RowSideColors = brewer.pal(4, "Set2")[factor(hc2$labels)])