| HeatmapAtomic | R Documentation |
Core implementation for drawing a single heatmap using
ComplexHeatmap::Heatmap. This function takes pre-processed data
(already in long format with resolved row/column identifiers) and handles
colour mapping, cell rendering, annotation construction, and the final
draw() call. It is the workhorse behind the exported
Heatmap function and is also reused by
LinkedHeatmapAtomic (via return_ht = TRUE).
HeatmapAtomic(
data,
values_by,
values_fill = NA,
rows_by = NULL,
rows_split_by = NULL,
columns_by = NULL,
columns_split_by = NULL,
palette = "RdBu",
palcolor = NULL,
palreverse = FALSE,
pie_size_name = "size",
pie_size = NULL,
pie_values = "length",
pie_group_by = NULL,
pie_palette = "Spectral",
pie_palcolor = NULL,
bars_sample = 100,
label = scales::label_number_auto(),
label_size = 10,
label_color = "black",
label_name = "label",
mark = identity,
mark_color = "black",
mark_size = 1,
mark_name = "mark",
violin_fill = NULL,
boxplot_fill = NULL,
dot_size = 8,
dot_size_name = "size",
legend_items = NULL,
legend_discrete = FALSE,
legend.position = "right",
legend.direction = "vertical",
lower_quantile = 0,
upper_quantile = 0.99,
lower_cutoff = NULL,
upper_cutoff = NULL,
add_bg = FALSE,
bg_alpha = 0.5,
keep_na = FALSE,
keep_empty = FALSE,
add_reticle = FALSE,
reticle_color = "grey",
cluster_columns = TRUE,
cluster_rows = TRUE,
show_row_names = NULL,
show_column_names = NULL,
border = TRUE,
title = NULL,
column_title = NULL,
row_title = NULL,
na_col = "grey85",
row_names_side = "right",
column_names_side = "bottom",
row_annotation = NULL,
row_annotation_side = NULL,
row_annotation_palette = NULL,
row_annotation_palcolor = NULL,
row_annotation_type = NULL,
row_annotation_params = NULL,
row_annotation_agg = NULL,
column_annotation = NULL,
column_annotation_side = NULL,
column_annotation_palette = NULL,
column_annotation_palcolor = NULL,
column_annotation_type = NULL,
column_annotation_params = NULL,
column_annotation_agg = NULL,
flip = FALSE,
alpha = 1,
seed = 8525,
padding = 15,
base_size = 1,
aspect.ratio = NULL,
draw_opts = list(),
return_ht = FALSE,
layer_fun_callback = NULL,
cell_type = "tile",
cell_agg = NULL,
...
)
data |
A data frame in long format. Each row represents one observation; columns specify row/column membership and the value to encode as colour. |
values_by |
A character of column name in |
values_fill |
A value used to fill missing cells in the matrix.
Default |
rows_by |
A vector of column names in |
rows_split_by |
A character of column name in |
columns_by |
A vector of column names in |
columns_split_by |
A character of column name in |
palette |
A character string naming a palette (see
|
palcolor |
A custom colour vector overriding |
palreverse |
A logical value indicating whether to reverse the palette. Default is FALSE. |
pie_size_name |
Legend title for the pie size. |
pie_size |
A numeric value or function returning the pie radius. When a function, it receives the count of groups in the pie. |
pie_values |
A function or string (convertible via
|
pie_group_by |
A character of column name in |
pie_palette, pie_palcolor |
Palette and custom colours for pie slice fill colours. |
bars_sample |
Number of observations sampled per cell when
|
label |
A function to compute text labels when
|
label_size |
Default point size for label text (used as fallback
when the |
label_color |
Default colour for label text (fallback). |
label_name |
Legend title for the label colour scale. The legend
is shown automatically when the |
mark |
A function to compute mark symbols when
|
mark_color |
Default mark colour (fallback). |
mark_size |
Default mark stroke width ( |
mark_name |
Legend title for the mark colour scale. |
violin_fill |
A character vector of colours to use as fill for
violin plots when |
boxplot_fill |
A character vector of colours to use as fill for
boxplots when |
dot_size |
Dot size when |
dot_size_name |
Legend title for the dot size. |
legend_items |
A named numeric vector specifying custom legend entries for the main colour scale. Names become the displayed labels. |
legend_discrete |
Logical; if |
legend.position |
A character string specifying the position of the legend.
if |
legend.direction |
A character string specifying the direction of the legend. |
lower_quantile, upper_quantile, lower_cutoff, upper_cutoff |
Quantile or explicit cutoffs for clipping the colour scale. Applied
to aggregated values for |
add_bg |
Logical; if |
bg_alpha |
Numeric in |
keep_na |
A logical value or a character to replace the NA values in the data.
It can also take a named list to specify different behavior for different columns.
If TRUE or NA, NA values will be replaced with NA.
If FALSE, NA values will be removed from the data before plotting.
If a character string is provided, NA values will be replaced with the provided string.
If a named vector/list is provided, the names should be the column names to apply the behavior to,
and the values should be one of TRUE, FALSE, or a character string.
Without a named vector/list, the behavior applies to categorical/character columns used on the plot,
for example, the |
keep_empty |
One of FALSE, TRUE and "level". It can also take a named list to specify
different behavior for different columns. Without a named list, the behavior applies to the
categorical/character columns used on the plot, for example, the
|
add_reticle |
Logical; if |
reticle_color |
Colour for the reticle lines. |
cluster_columns |
Logical; cluster the columns. If |
cluster_rows |
Logical; cluster the rows. If |
show_row_names |
Logical; show row names. If |
show_column_names |
Logical; show column names. If |
border |
A logical value indicating whether to draw borders around
the heatmap. If |
title |
The global (column) title of the heatmap. |
column_title |
Character string/vector used as the column group annotation title. |
row_title |
Character string/vector used as the row group annotation title. |
na_col |
Colour for |
row_names_side |
Side for row names. Default |
column_names_side |
Side for column names. Default |
row_annotation |
A structured list specifying row annotations.
Same format as |
row_annotation_side |
Deprecated: use
|
row_annotation_palette |
Deprecated: use
|
row_annotation_palcolor |
Deprecated: use
|
row_annotation_type |
Deprecated: use
|
row_annotation_params |
Deprecated: use
|
row_annotation_agg |
Deprecated: use
|
column_annotation |
A structured list specifying column annotations. Each entry is a named list with sub-keys:
Shortcuts:
Special keys:
|
column_annotation_side |
Deprecated: use
|
column_annotation_palette |
Deprecated: use
|
column_annotation_palcolor |
Deprecated: use
|
column_annotation_type |
Deprecated: use
|
column_annotation_params |
Deprecated: use
|
column_annotation_agg |
Deprecated: use
|
flip |
Logical; if |
alpha |
Alpha transparency for heatmap cells in |
seed |
The random seed to use. Default is 8525. |
padding |
Padding around the heatmap in CSS order (top, right,
bottom, left). Supports 1–4 values. Default 15 (mm). Note that
this is different from |
base_size |
A positive numeric scalar used as a scaling factor for the overall heatmap size. Default 1 (no scaling). Values > 1 enlarge all cell dimensions proportionally. |
aspect.ratio |
Height-to-width ratio of a single heatmap cell.
When |
draw_opts |
A named list of additional arguments passed to
|
return_ht |
Logical; if |
layer_fun_callback |
A function to add custom graphical layers on
top of each heatmap cell. Receives |
cell_type |
The type of cell to render. One of |
cell_agg |
A function to aggregate values within each cell when
|
... |
Additional arguments passed to
|
An object of heatmap that is wrapped by patchwork::wrap_plots()
Annotation resolution — row and column annotation
parameters (side, type, palette, params, aggregation) are
resolved with alias support (.row, .col,
.rows.split, etc.) so that built-in name/split annotations
and user-defined annotations can be configured uniformly.
Keep-NA / keep-empty handling — keep_na and
keep_empty are processed per column to control whether
NA values and empty factor levels are preserved in the
data before constructing the heatmap matrix.
Flip — when flip = TRUE, row and column
parameters are swapped transparently so the caller does not need
to manually swap every argument.
Cell dimension calculation — cell width and height are
pre-computed from cell_type, aspect.ratio,
base_size, and the unique row/column counts (accounting
for split groups). These are passed as explicit
"inches" units to ComplexHeatmap::Heatmap() so
cells have guaranteed physical sizes.
Colour mapping — the main colour scale is built from
palette / palcolor with optional quantile-based
or explicit cutoff clamping.
Cell function dispatch — depending on
cell_type, the appropriate cell_fun or
layer_fun is installed (tile, bars, label, mark,
label+mark, dot, violin, boxplot, pie).
Annotation construction — row and column annotations
are built via ComplexHeatmap::HeatmapAnnotation() using
the resolved type and parameters.
Drawing — the heatmap is drawn via
ComplexHeatmap::draw() with controlled padding and legend
collection. When return_ht = TRUE, the prepared
Heatmap object is returned without drawing.
Dimension attributes — the returned object carries
height / width attributes (in inches) and
cell_w / cell_h attributes for downstream layout
calculations.
The label and mark functions can take 1, 3, or 5
arguments. The first argument is always the aggregated value for a
single cell. With 3 arguments, the second and third are the row and
column indices. With 5 arguments, the fourth and fifth are the row
and column names. The function should return one of:
NA — nothing is drawn for this cell.
A character scalar — used as the label text / mark type; default size and colour are used.
A named list with fields label/mark,
size, color, legend, and order
(all optional; smaller order appears first in the
legend).
For label cells with custom indices, use
ComplexHeatmap::pindex() to translate between data and heatmap
coordinates.
Primitives: - (h-line), | (v-line),
+ (cross), / (l-diag), \ (r-diag),
x (both diags), o (circle), ()
(edge-touching circle), <> (diamond).
With rectangular border: [], [-],
[|], [+], [/], [\], [x],
[o], [()], [<>].
With full circle: (-), (|),
(+), (/), (\), (x), (o),
(<>).
With diamond: <->, <|>, <+>,
</>, <\>, <x>, <o>.
Octagon: {}, {-}, {|},
{+}, {/}, {\}, {x},
{o}, {()}, {<>}.
Combinations: e.g. [(|)], [(-)],
[(+)], [(/)], [(\], [(x)],
[(o)], [(<>)].
Row and column annotations are configured via the
row_annotation / column_annotation structured list
arguments. Built-in name annotations (for rows_by /
columns_by) and split annotations (for rows_split_by /
columns_split_by) are added automatically and can be configured
using the aliases .row / .col and .row.split /
.col.split as keys in the annotation list. Setting an alias
entry's params to FALSE disables that annotation.
.default provides default values inherited by all entries
(with recursive merge for params). Ordering within each side:
name annotations are closest to the body, split annotations farthest
away, user-defined annotations in between.
Removed parameters: rows_palette, rows_palcolor,
columns_palette, columns_palcolor,
columns_split_palette, columns_split_palcolor,
rows_split_palette, rows_split_palcolor — use
row_annotation/column_annotation with
sub-key palette/palcolor and alias
.row / .row.split / .col / .col.split.
Also removed:
row_name_annotation, row_name_legend,
column_name_annotation, column_name_legend — set
row_annotation = list(.row = list(params = FALSE)) /
column_annotation = list(.col = list(params = FALSE)).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.