I am having issues with pheatmap legend annotations. I want to annotate my columns with metadata from my coldata (working with RNAseq, DESeq2).
DESeq2:
dds <- DESeqDataSetFromMatrix(countData = counts, # Raw expression counts.
colData = coldata, # Metadata with age & sex lables.
design = ~ age)
dds <- DESeq(dds, test="LRT", reduced = ~ 1) # LRT test for model fitting.
res <- results(dds)
vsd <- vst(dds, blind = FALSE)
plotPCA(vsd, intgroup = c("age","sex", "batch"), returnData = FALSE)
# Create annotation
heat_anno <- as.data.frame(colData(vsd)[,c("age", "sex")])
heat_colors <- list(
sex = c("M" = "#01bfc5", "F" = "salmon"))
Simplified version of the heatmap code:
pheatmap(mat = assay(vsd[genes, ]),
cluster_rows = TRUE,
cluster_cols = FALSE,
annotation_col = heat_anno,
labels_col = coldata$age)
The result looks like that:
The colors on top of the heatmap are correctly assigned to respective values. However, as you can see in my colnames, the legend for age incorrectly displays the min and max values as 2 and 8 instead of my 0.6 - 9.8. I want to set the legend annotation to 0 and 10 (or at the very least to min and max of my coldata$age). Does anybody know how I could do this? breaks and legend_breaks modifies the color gradient of the heatmap values themselves (here scaled expression), but not additional annotations.
Try switching to ComplexHeatmap - it gives you far more granular control than pheatmap can.