pheatmap: how to use legend information as row annotation?
0
0
Entering edit mode
6.6 years ago
n85825 • 0

I am using below code in pheatmap to generate the first heatmap.

oz <- DESeq(oz)
rld <- rlog(oz)
topVarGenes <- head(order(rowVars(assay(rld)), decreasing = TRUE), 35)
mat  <- assay(rld)[topVarGenes, ]
mat  <- mat - rowMeans(mat)
anno_col <- as.data.frame(colData(rld)[, c("time","treatment")])
anno_row <- data.frame(category = c(rep("pathway_1", 8), 
rep("CATEGORY_2", 2), rep("pathway_3", 10), 
rep("CATEGORY_4", 4), rep("limited_5", 11)), stringsAsFactors = FALSE)
mixed_name <- cbind(mat[,0],anno_row)
pheatmap(mat, annotation_col = anno_col, annotation_row = mixed_name, scale = "column", 
cluster_cols = F, cluster_rows= F, clustering_distance_rows = "correlation", 
clustering_distance_cols = "correlation", clustering_method = "average",  
gaps_row=c(8,10,20,24), 
cellheight = 6, cellwidth = 10, border_color=NA, fontsize_row = 6)

first heatmap

Now, my question is that what should be added to the above code to have the "category" legend on the left of the heatmap and close to each category color, like the second figure that I have highlighted in red.

In advance, thanks for your helps!

enter image description here

R pheatmap legend annotation • 17k views
ADD COMMENT
0
Entering edit mode

Have you tried annotation_name_row=T? I think the legend position is an open issue.

ADD REPLY
0
Entering edit mode

Yes, I did. But nothing has changed.

ADD REPLY
1
Entering edit mode

You may want to take a look at the ComplexHeatmap package, with which you can definitely change the position of the legends and legend text.

ADD REPLY
0
Entering edit mode

I think you are right! The only way is switching to ComplexHeatmap package! Thank you!

ADD REPLY
0
Entering edit mode

Yes, it will take 1 day to switch, if you have that time. However, once you move, you will never return to the other heatmap functions. The vignettes for ComplexHeatmap are very good.

ADD REPLY

Login before adding your answer.

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