how to display multiple row annotations on pheatmap
1
2
Entering edit mode
6.4 years ago

I am interested in adding multiple row annotations to my heatmap using the pheatmap function in R (example: https://stackoverflow.com/questions/41628450/r-pheatmap-change-annotation-colors-and-prevent-graphics-window-from-popping-up). The examples I see online all give only one annotation. What is the easy way to extend it to multiple row annotations?

pheatmap • 29k views
ADD COMMENT
1
Entering edit mode

If you hablve a data frame or matrix with your gene names annotated for each category. Then you can easily parse it in pheatmap as annotation_row= . Check the pheatmap tutorial. Alternatively if it's on the fly then you have to create vectors of the category with your gene names or rownames that you intend to project and create a data frame with them. Once done while you write code for the pheatmap just parse that data frame in to the row annotate handler. It should work.

ADD REPLY
0
Entering edit mode

I have a data frame for the annotation, and I tried doing it, as you've mentioned. For some reason, I always get this error: Error in cut.default(a, breaks = 100) : 'x' must be numeric. Could you help me understand what this error means?

ADD REPLY
0
Entering edit mode

I would encourage you to search the error in this forum or Google or StackOverflow. In case you do not find it. Please write a new post in those mentioned forums detailing your problem scope, code snippet, and error, so that we can better assist.

ADD REPLY
0
Entering edit mode

Thanks for the comments; I made it to work for categorial variables. Now I am trying to add row annotations for categorial variables. In otherwords I am trying to add a heatmap on continuous variables as row annotations for another heatmap. Do I have to to define the bin sizes and treat the continuous variables as categorial variables, or is there a easier way to get around this step?

Thanks, Lavanya

ADD REPLY
0
Entering edit mode

you can use the continuous annotations as is, pheatmap will take care of it

ADD REPLY
14
Entering edit mode
6.4 years ago

from the pheatmap help:

# make test matrix
test = matrix(rnorm(200), 20, 10)
test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3
test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2
test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4
colnames(test) = paste("Test", 1:10, sep = "")
rownames(test) = paste("Gene", 1:20, sep = "")

# define the annotation
annotation_row = data.frame(
                    GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6))),
                  AdditionalAnnotation = c(rep("random1", 10), rep("random2", 10))
                )
rownames(annotation_row) = paste("Gene", 1:20, sep = "")

pheatmap(test, annotation_row = annotation_row)
ADD COMMENT
0
Entering edit mode

This is a correct answer. Why has it not bee selected so?

ADD REPLY
2
Entering edit mode

Indeed it is correct, and here is the proof: d

We are volunteers here and it is very difficult to keep track of activity in each and every thread. Apart from vacation/holidays, Biostars typically receives >1000 user visits per hour, throughout the entire day.

I have marked the answer as accepted myself.

ADD REPLY

Login before adding your answer.

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