Question: Help with adding a row color side bar using pheatmap??
0
gravatar for rockquark
3.8 years ago by
rockquark10
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:

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 • 2.8k views
ADD COMMENTlink modified 3.8 years ago by mastal5112.0k • written 3.8 years ago by rockquark10
0
gravatar for mehran.karimzade
3.8 years ago by
Canada
mehran.karimzade170 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)

to:

rownames(categoriesrow) <- rownames(dummymat)

Would work.

ADD COMMENTlink modified 3.8 years ago • written 3.8 years ago by mehran.karimzade170
0
gravatar for mastal511
3.8 years ago by
mastal5112.0k
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 3.8 years ago by mastal5112.0k
Please log in to add an answer.

Help
Access

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