How can I associate specific colors to specific data for the color bar in heatmaps in R?
0
0
Entering edit mode
8.4 years ago
rockquark ▴ 10

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 • 4.0k views
ADD COMMENT

Login before adding your answer.

Traffic: 3230 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