Visualizes a network adjacency/weight matrix as a heatmap. Supports single networks, multi-cluster networks (block diagonal), and multi-layer networks (group_tna).
plot_heatmap(
x,
cluster_list = NULL,
cluster_spacing = 0,
show_legend = TRUE,
legend_position = "right",
legend_title = "Weight",
colors = "viridis",
limits = NULL,
midpoint = NULL,
na_color = "grey90",
show_values = FALSE,
value_size = 2.5,
value_color = "black",
value_fontface = "plain",
value_fontfamily = "sans",
value_halo = NULL,
value_digits = 2,
show_diagonal = TRUE,
diagonal_color = NULL,
cluster_labels = TRUE,
cluster_borders = TRUE,
border_color = "black",
border_width = 0.5,
row_labels = NULL,
col_labels = NULL,
show_axis_labels = TRUE,
axis_text_size = 8,
axis_text_angle = 45,
title = NULL,
subtitle = NULL,
xlab = NULL,
ylab = NULL,
threshold = 0,
aspect_ratio = 1,
...
)A ggplot2 object.
Network input: matrix, CographNetwork, cograph_network, tna,
igraph, group_tna, or a list-like object with a $weights matrix.
Optional list of character vectors defining node clusters. Creates a block-structured heatmap with clusters along diagonal.
Gap size between clusters (in cell units). Default 0.
Logical: display color legend? Default TRUE.
Position: "right" (default), "left", "top", "bottom", "none".
Title for legend. Default "Weight".
Color palette: vector of colors for gradient, or a palette name ("viridis", "heat", "blues", "reds", "greens", "diverging"). Default "viridis".
Numeric vector c(min, max) for color scale. NULL for auto.
Midpoint for diverging scales. NULL for auto (0 if data spans neg/pos).
Color for NA values. Default "grey90".
Logical: display values in cells? Default FALSE.
Text size for cell values. Default 2.5.
Color for cell value text. Default "black".
Font face for values: "plain", "bold", "italic", "bold.italic". Default "plain".
Font family for values: "sans", "serif", "mono". Default "sans".
Halo color behind value labels for readability on dark cells. Set to a color (e.g., "white") to enable, or NULL (default) to disable.
Decimal places for values. Default 2.
Logical: show diagonal values? Default TRUE.
Accepted for API compatibility; diagonal cells currently
use the active fill scale unless hidden with show_diagonal = FALSE.
Logical: show cluster/layer labels? Default TRUE.
Logical: draw borders around clusters? Default TRUE.
Color for cluster borders. Default "black".
Width of cluster borders. Default 0.5.
Row labels. NULL for auto (rownames or indices).
Column labels. NULL for auto (colnames or indices).
Logical: show axis tick labels? Default TRUE.
Size of axis labels. Default 8.
Angle for x-axis labels. Default 45.
Plot title. Default NULL.
Plot subtitle. Default NULL.
X-axis label. Default NULL.
Y-axis label. Default NULL.
Minimum absolute value to display. Values with
abs(value) < threshold are set to zero. Default 0.
Aspect ratio. Default 1 (square cells).
Additional arguments (currently unused).
For multi-cluster networks, provide cluster_list as a named list where
each element is a vector of node names belonging to that cluster. The heatmap
will be reordered to show clusters as blocks along the diagonal.
For group_tna objects (multiple separate networks), each network becomes a diagonal block. Off-diagonal blocks are empty (no inter-layer edges).
set.seed(1)
m <- matrix(runif(25), 5, 5)
rownames(m) <- colnames(m) <- LETTERS[1:5]
plot_heatmap(m)
# With clusters, values, and a different color scale
clusters <- list(G1 = c("A","B"), G2 = c("C","D","E"))
plot_heatmap(m, cluster_list = clusters, colors = "heat", show_values = TRUE)
Run the code above in your browser using DataLab