Question: pheatmap: how to use legend information as row annotation?
gravatar for n85825
2.8 years ago by
n858250 wrote:

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 <-[, 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",  
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

annotation pheatmap R legend • 7.1k views
ADD COMMENTlink modified 2.8 years ago • written 2.8 years ago by n858250

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

ADD REPLYlink written 2.8 years ago by Devon Ryan98k

Yes, I did. But nothing has changed.

ADD REPLYlink written 2.8 years ago by n858250

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 REPLYlink written 2.8 years ago by Kevin Blighe69k

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

ADD REPLYlink written 2.8 years ago by n858250

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 REPLYlink written 18 months ago by Kevin Blighe69k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2147 users visited in the last hour