Question: Pheatmap Annotation
5
gravatar for James
4.8 years ago by
James60
James60 wrote:

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 • 20k views
ADD COMMENTlink modified 2.3 years ago by wm90 • written 4.8 years ago by James60

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 REPLYlink modified 4.8 years ago • written 4.8 years ago by Josh Herr5.5k

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 REPLYlink written 4.8 years ago by James60
1

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 REPLYlink modified 4.8 years ago • written 4.8 years ago by Josh Herr5.5k
7
gravatar for wm
2.3 years ago by
wm90
China
wm90 wrote:

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 COMMENTlink modified 2.3 years ago • written 2.3 years ago by wm90

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

Even the column annotation doesnot 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 REPLYlink modified 23 months ago • written 23 months ago by siddharth.sethi5190

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

ADD REPLYlink written 23 months ago by siddharth.sethi5190

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

ADD REPLYlink written 23 months ago by msameet30

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

ADD REPLYlink written 12 months ago by hongen.hugo.xu0
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: 1431 users visited in the last hour