Help with adding a row color side bar using pheatmap??
2
0
Entering edit mode
8.2 years ago
rockquark ▴ 10

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

R software error • 5.1k views
ADD COMMENT
0
Entering edit mode
8.2 years ago

I executed your script and dimensions of your categoriesrow are 10X2 and you cannot specify 10 column names to a dataframe with 2 columns.

Change this:

colnames(categoriesrow) <- rownames(dummymat)

to:

rownames(categoriesrow) <- rownames(dummymat)

Would work.

ADD COMMENT
0
Entering edit mode
8.2 years ago
mastal511 ★ 2.1k

The problem that I can see with your code is that categoriesrow is a data frame with 2 columns, named TDC and Bcells.

The line

colnames(categoriesrow) <- rownames(dummymat)

will give an error, because dummymat has 10 rows, the gene names.

Presumably what you want is

rownames(categoriesrow) <- rownames(dummymat)

ADD COMMENT

Login before adding your answer.

Traffic: 3236 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6