ggheatmap()
Published

August 7, 2025

Heatmap with Ordering Weights

library(ggalign)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'ggalign'
#> The following object is masked from 'package:ggplot2':
#> 
#>     element_polygon
set.seed(123)
# Prepare heatmap matrix
mat <- matrix(
    rnorm(100, mean = 0, sd = 2),
    nrow = 10, ncol = 10,
    dimnames = list(paste0("G", 1:10), paste0("S", 1:10))
)

Order the observations based on the means.

ggheatmap(mat) +
    anno_left() +
    align_order(rowMeans)
#> → heatmap built with `geom_tile()`