ggheatmap()
Published

August 7, 2025

Heatmap with Annotations

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

Annotate top with color bars:

ggheatmap(mat) +
    anno_top(size = unit(1, "cm")) +
    align_kmeans(centers = 3L) +
    ggalign(data = NULL) +
    geom_tile(aes(y = 1L, fill = .panel, color = .panel)) +
    theme_no_axes("y")
#> → heatmap built with `geom_tile()`

Annotate both left and right positions:

ggheatmap(mat) +
    anno_right(size = 0.3) +
    align_dendro() +
    anno_left(size = 0.3) +
    ggalign(rowSums) +
    geom_bar(aes(x = value, y = .y, fill = value),
        orientation = "y", stat = "identity"
    ) +
    scale_fill_viridis_c(option = "A")
#> → heatmap built with `geom_tile()`