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
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?
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.
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...