2

I am trying to display the result of a clustering algorithm based on k-means as pheatmap. For this, I use the procedure suggested here: R draw kmeans clustering with heatmap

Now the problem is, that I would like to add a color scheme highlighting the clusters, something similar to the "RowSideColors"-option in heatmap and heatmap.2. As to pheatmap, I found only the annotation option, but this works columnwise instead of rowwise. Is there a way to highlight the row clusters in pheatmap?

Another idea that I had is to add the cluster-column as a separate color within the heatmap. However, I would need to use another colour scheme than for the rest of the heatmap, so I am not sure if it's possible.

Community
  • 1
  • 1
AnjaM
  • 2,941
  • 8
  • 39
  • 62

1 Answers1

5

Now there is an annotation_row parameter in pheatmap package:

library(pheatmap)

# define a matrix
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# annotate rows
annotation_row = data.frame(
GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6))))
rownames(annotation_row) = paste("Gene", 1:20, sep = "")

# plot pheatmap
pheatmap(test, annotation_row = annotation_row)
wikiselev
  • 333
  • 5
  • 10