Another option: ggalign package
The usage of ggalign
is simple if you're familiar with ggplot2
syntax, the
typical workflow includes:
- Initialize the layout using
ggheatmap()
or ggstack()
.
- Customize the layout with:
align_group()
: Group layout axis into panel with a group variable.
align_kmeans()
: Group layout axis into panel by kmeans.
align_reorder()
: Reorder layout observations based on statistical weights
or by manually specifying the observation index.
align_dendro()
: Reorder or Group layout based on hierarchical clustering.
- Adding plots with
ggalign()
or ggpanel()
, and then layer additional
ggplot2 elements such as geoms, stats, or scales.
Here is the solution for this issue:
library(ggalign)
#> Loading required package: ggplot2
mat <- data.frame(matrix(rnorm(100), nrow = 20))
ggstack(mat, "h", sizes = unit(c(2, 1, 1), c("cm", "null", "null"))) +
ggheatmap() +
hmanno("t", free_spaces = "l") +
align_dendro(aes(color = branch), k = 3L) +
scale_color_brewer(palette = "Set2") +
hmanno("l", size = unit(2, "cm")) +
align_dendro(aes(color = branch), k = 4L) +
scale_color_brewer(palette = "Set1") +
ggheatmap() +
hmanno("t") +
align_dendro(aes(color = branch), k = 3L) +
scale_color_brewer(palette = "Set2") +
hmanno("r", size = unit(2, "cm")) +
align_dendro(aes(color = branch), k = 4L) +
scale_color_brewer(palette = "Set1")
Created on 2024-10-09 with [reprex v2.1.0](https://reprex.tidyverse.org)
~
Indeed. ComplexHeatmap renders all other heatmap packages useless by providing any features one might want. pheatmap especially is pretty obsolete, as CH was built to address its shortcomings - as the developer puts it:
FWIW pheatmaps can be readily aligned with cowplot. But yes, in general it makes sense to move onto ComplexHeatmap. Historically it wasn't the fastest which made me stick to pheatmap for a while. But it has since overtaken it in most regards.
Thank you - I was unaware of the speed difference. I loved the features and how intuitive it was. Has it gotten better than pheatmap in terms of speed as well?
I mean I'm talking like years ago back when I was doing my PhD. We use ComplexHeatmap a lot for plotting single-cell and CNA data so the speed is definitely much better now.
You have to factor in that before I started my degree I never touched R so there might have been an element of competence at play also.