Question: Help with adding a row color side bar using pheatmap??
gravatar for rockquark
4.6 years ago by
rockquark10 wrote:

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:

# 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 • 3.4k views
ADD COMMENTlink modified 4.6 years ago by mastal5112.0k • written 4.6 years ago by rockquark10
gravatar for mehran.karimzade
4.6 years ago by
mehran.karimzade180 wrote:

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)


rownames(categoriesrow) <- rownames(dummymat)

Would work.

ADD COMMENTlink modified 4.6 years ago • written 4.6 years ago by mehran.karimzade180
gravatar for mastal511
4.6 years ago by
mastal5112.0k wrote:

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 COMMENTlink written 4.6 years ago by mastal5112.0k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 617 users visited in the last hour