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,871
  • 6
  • 37
  • 58

2 Answers2

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
  • 323
  • 3
  • 9
-1

Well, you can use heatmap or heatmap.2 directly as pheatmap has no kind of this parameter. Actually, I have the similar task.enter image description here

Zhilong Jia
  • 2,237
  • 1
  • 20
  • 32