Pheatmap Annotation
1
7
Entering edit mode
11.7 years ago
James ▴ 80

I'm having trouble modifying the following codes from pheatmap package to annotate my heatmap of data (size - 118 rows by 2 cols):

 EDIT:
# Generate some data
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 = "")

# Generate column annotations
annotation = data.frame(Var1 = factor(1:10 %% 2 == 0, labels = c("Class1", "Class2")), Var2 = 1:10)
annotation$Var1 = factor(annotation$Var1, levels = c("Class1", "Class2", "Class3"))
rownames(annotation) = paste("Test", 1:10, sep = "")

pheatmap(test, annotation = annotation)
pheatmap(test, annotation = annotation, annotation_legend = FALSE)
pheatmap(test, annotation = annotation, annotation_legend = FALSE, drop_levels = FALSE)

# Specify colors
Var1 = c("navy", "darkgreen")
names(Var1) = c("Class1", "Class2")
Var2 = c("lightgreen", "navy")

ann_colors = list(Var1 = Var1, Var2 = Var2)

pheatmap(test, annotation = annotation, annotation_colors = ann_colors, main = "Example with all the features")

My intention is to have class 1 and class 2 replaced by Exp1 and Exp2, respectively, when the annotation is displayed and the two column tops with two colors as "navy", "darkgreen". I only need the var1 part of the code for my purpose.

I hope someone can help me out. Thanks

r heatmap • 74k views
ADD COMMENT
0
Entering edit mode

I tried your code with my own data (since there is no data frame here) and can get it to plot out, but I'm not sure exactly how you want your heatmaps to look. Not sure how much is inherent to my data. I guess this is more a graphing aesthetics question, just not completely sure how you want it to look. Have you tried over on the R list at stack exchange?

ADD REPLY
0
Entering edit mode

Thanks Josh. I've edited the post to show how the data was generated in the pheatmap tutorial. I have also checked and psoted at the stack exchange. All I want is to be able to plug in my own data (118 rows by 2 cols) and label the two columns as Exp 1 and Exp2, respectively, in place of class1 and class2 as in the tutorial.

ADD REPLY
1
Entering edit mode

Thanks for the update James, you also pulled a cool rownames(annotation) move which I didn't know about. That's going to come in handy for me.

I don't really have enough R skills to tell you how to fix this. It graphs great for me, but I see what you want to do and don't know how to fix it off the top of my head. When I have run into this issue in the past I usually save the graph as an SVG or EPS format and then edit colors, boxes, and text in something like Adobe Illustrator. Wish I could be more help here...

ADD REPLY
11
Entering edit mode
9.3 years ago
wm ▴ 570

According to my understanding, you just want to change the name of annotation from class1, class2 to Exp1 and Exp2.

The original figure like this:

library(pheatmap)
# Generate some data
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 = "")
# original figure
pheatmap(test)

original

# Add annotation as described above, and change the name of annotation
annotation <- data.frame(Var1 = factor(1:10 %% 2 == 0, labels = c("Exp1", "Exp2")))
rownames(annotation) <- colnames(test) # check out the row names of annotation
pheatmap(test, annotation = annotation)

Add annotation on column

# change the color of annotation to what you want: (eg: "navy", "darkgreen")
Var1        <- c("navy", "darkgreen")
names(Var1) <- c("Exp1", "Exp2")
anno_colors <- list(Var1 = Var1)
pheatmap(test, annotation = annotation, annotation_colors = anno_colors)

add annotation, change color

ADD COMMENT
0
Entering edit mode

Hi , have you tried annotation of the rows. It seems to be not working.

Even the column annotation does not work if you use the argument annotation_col. Using the argument annotation defaults to column annotation . So I am not able to get row annotations with annotation_row argument. seems like a bug

ADD REPLY
0
Entering edit mode

Tried with Windows R , it works with windows. There is a bug in Linux version. version = pheatmap_1.0.8

ADD REPLY
0
Entering edit mode

It seems to be working just okay on Mac OS X.

ADD REPLY
0
Entering edit mode

it works. Thanks. Do you know how can I label "EXP1" as "EX^p1" (p1 is in superscript)?

ADD REPLY

Login before adding your answer.

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