Making a pheatmap legend with superscripts
0
0
Entering edit mode
6 weeks ago

Is it possible to get the legend in a pheatmap to output a Genotype with a superscript in the name?

I've tried using expression(p^n), but it gets flattened to text in the annotation data frame

annotation <- data.frame(row.names= rownames(anno))
annotation$Genotype <- anno$Genotype
annotation$Day_factor <- anno$Day_factor

ann_colors <- list(Genotype = c("Control" = "skyblue", "not_control" = "pink"), 
Day_factor = c("0" = "#EDF8FB", "7" = "#BEE6E7", "14" = "#83CEBC", "21" = "#4DB486", "28" = "#2CA25F"))

pheatmap(first_heatmap, main = "First Heatmap", annotation_colors = ann_colors, 
color = heatmap_colors, show_rownames=T, scale = "row", cluster_col = F , cluster_rows = T, show_colnames = F, 
annotation= annotation, treeheight_row = 0) 
pheatmap • 346 views
ADD COMMENT
1
Entering edit mode

Can you switch to ComplexHeatmap? It supports complex formatting with grid.text.

ADD REPLY
0
Entering edit mode

Yeah, that works, even without grid.text,

col_ha <- HeatmapAnnotation(df = annotation, col=ann_colors, annotation_legend_param = list( Genotype=list(labels = expression("Control", p^{n})))) 
Heatmap(t(scale(t(first_heatmap))), name = " ", cluster_columns = FALSE, show_row_dend = FALSE, show_column_names = FALSE, top_annotation = col_ha)

It's because ComplexHeatmap can be given an expression vector which will overwrite the default legend labels (so can ggplot2), while as far as I can tell, pheatmap can't.

ADD REPLY
0
Entering edit mode

I don't even bother with pheatmap/heatmap.n when ComplexHeatmap has basically everything. I'd switch if that's an option, you'll never have to switch to a different heatmap software ever.

ADD REPLY
0
Entering edit mode

Have you tried something like this? plot.new() text(0.5, 0.7, labels = quote("Interface area " * (Å ^ 2)))

ADD REPLY
0
Entering edit mode

I don't think that would work; I've got two different characteristics in the annotation data, plus the heatmap color scheme itself; how would it know what text to replace? I'm also not sure that quoting like that is sufficient to get the supercripts to look like supercripts. Expression seemed to be the way to do that.

ADD REPLY

Login before adding your answer.

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