Hi All,
I'm trying to figure out the best way to associate a color side bar to different factors for the rows in my data set when using pheatmap.
Here is a code with a dummy data set to illustrate what I want:
require(pheatmap)
# dummy data
dummymat = matrix(rnorm(100), 10, 10)
colnames(dummymat) = paste("Patient", 1:10, sep = "")
rownames(dummymat) = paste("Gene", 1:10, sep = "")
# create a data frame with the patients categories
categories <- data.frame(Sex = factor(sample(c("Male", "Female"),size = 10,replace = T), labels = c("Male", "Female")),
Stage= factor(sample(c('I','II','III'),size = 10,replace = T), labels = c('I','II','III')))
rownames(categories) <- colnames(dummymat)
categoriesrow <- data.frame(TDC = factor(sample(c("BB", "DD"),size = 10,replace = T), labels = c("BB", "DD")), Bcells= factor(sample(c('WW','RR','TT'),size = 10,replace = T), labels = c('WW','RR','TT')))
colnames(categoriesrow) <- rownames(dummymat)
pheatmap(dummymat, annotation_col = categories, annotation_row = categoriesrow)
With the code above I'm able to create a very nice column color bar (if I take out the "annotation_row = categoriesrow"), but once I try to create a row color bar I get errors. The error that occurs is after I process "colnames(categories) <- rownames(dummymat)"
Error in colnames<-
(*tmp*
, value = c("Gene1", "Gene2", "Gene3", "Gene4", :
'names' attribute [10] must be the same length as the vector [2]
Can someone please let me know the best way to achieve what I want? I would appreciate any help!
Thanks, Afshin