This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I associate specific colors to specific data for the color bar in heatmaps in R?

HI All,

I'm fairly in new with R, so any help is much appreciated. I'm in the process of making a heatmap using the pheatmap function. I'm adding a column color bar so that I can associate specific data in the header with specific colors in the color bar. So for example I want anything that contains the number 1 in the header of my entire data set to be labeled as Male and have a specific color associated with it in the column color bar.

I'm using the following code as an example to try to do this:

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("1", "2"),size = 10,replace = T), labels = c("Male", "Female")), Stage= factor(sample(c('Patient10','Patient9','patient5'),size = 10,replace = T), labels = c('I','II','III')))

rownames(categories) <- colnames(dummymat) 

pheatmap(dummymat, color = colorRampPalette(c("navy", "white", "firebrick3"))(50), clustering_method = "mcquitty",
         clustering_distance_rows = "euclidean", clustering_distance_cols = "euclidean",
         scale = 'none', annotation = categories)

Obviously from the above code I don't get what I want. I'm sure I using the wrong functions here to do this (since I'm a beginner in R)

Can anyone help with my question? I would really appreciate any input and help that anyone can give.

Thanks,
Afshin

r

0 answers

No answers yet.

Log in to answer this question.