View source: R/linkedheatmap.R
| LinkedHeatmapAtomic | R Documentation |
Draws two heatmaps side-by-side with spline link lines connecting matching
rows across the left and right heatmaps. This is the core implementation
layer — it takes a single data frame and a full set of left/right
parameters, delegates to HeatmapAtomic (with
return_ht = TRUE) to obtain prepared ComplexHeatmap::Heatmap
objects, extracts exact dimension information, and then assembles
everything into a composite grid layout.
LinkedHeatmapAtomic(
data,
left_values_by,
right_values_by,
left_rows_by,
right_rows_by,
left_columns_by,
right_columns_by,
left_columns_split_by = NULL,
right_columns_split_by = NULL,
left_pie_group_by = NULL,
right_pie_group_by = NULL,
rows_split_by = NULL,
values_fill = NA,
palette = "RdBu",
palcolor = NULL,
palreverse = FALSE,
pie_size_name = "size",
pie_size = NULL,
pie_values = "length",
pie_palette = "Spectral",
pie_palcolor = NULL,
bars_sample = 100,
label = identity,
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",
left_cluster_rows = NULL,
right_cluster_rows = NULL,
cluster_columns = NULL,
show_row_names = NULL,
show_column_names = NULL,
border = TRUE,
title = NULL,
title_params = NULL,
column_title = NULL,
row_title = NULL,
na_col = "grey85",
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,
links_span = 0.5,
link_width_by = NULL,
link_width_scale = 5,
link_color = "grey30",
link_alpha = 0.8,
alpha = 1,
seed = 8525,
padding = 15,
base_size = 1,
aspect.ratio = NULL,
draw_opts = list(),
layer_fun_callback = NULL,
cell_type = c("tile", "bars", "label", "mark", "label+mark", "mark+label", "dot",
"violin", "boxplot", "pie"),
cell_agg = NULL,
...
)
data |
A data frame in long format. Each row represents one observation; columns specify row/column membership for both left and right heatmaps as well as the values to encode as color. |
left_values_by, right_values_by |
Column name whose values determine the fill color of cells in the left / right heatmap. These are the primary data columns visualized by the colour scale. |
left_rows_by, right_rows_by |
Column name that defines the rows of the left / right heatmap. Each unique value becomes one row. |
left_columns_by, right_columns_by |
Column name that defines the columns of the left / right heatmap. Each unique value becomes one column. |
left_columns_split_by, right_columns_split_by |
Optional column name
to split the columns of the left / right heatmap into groups (passed to
|
left_pie_group_by, right_pie_group_by |
When |
rows_split_by |
Optional column name to split the rows of both
heatmaps into groups (passed as |
values_fill |
A value used to fill missing cells in the matrix
(passed to |
palette |
A character string naming a palette (see
|
palcolor |
A custom colour vector that overrides |
palreverse |
Logical; if |
pie_size_name |
Legend title for the pie size when
|
pie_size |
A numeric value or function returning the pie radius. When a function, it receives the count of groups in the pie and should return a radius. |
pie_values |
A function or string (convertible via
|
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 (used as fallback when
the |
label_name |
Legend title for the label colour scale. |
mark |
A function to compute mark symbols when
|
mark_color |
Default mark colour (fallback). |
mark_size |
Default mark stroke width in pt (fallback). |
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 where to place the
combined legend: |
legend.direction |
Legend stacking direction:
|
lower_quantile, upper_quantile |
Quantiles used for clipping the
colour scale when |
lower_cutoff, upper_cutoff |
Explicit cutoffs for the colour scale.
Values outside the range are clamped (winsorized). Override
|
add_bg |
Logical; if |
bg_alpha |
Numeric in |
keep_na, keep_empty |
Passed through to |
add_reticle |
Logical; if |
reticle_color |
Colour for the reticle lines. |
left_cluster_rows, right_cluster_rows |
Logical controlling whether
rows are clustered in the left / right heatmap. |
cluster_columns |
Logical; cluster columns in both heatmaps.
|
show_row_names, show_column_names |
Logical; show row/column names. |
border |
Logical; draw a border around each heatmap. Default
|
title |
A character string for the overall plot title. A function
can be used to generate a dynamic title from the default.
Note that, |
title_params |
A list of parameters passed to |
column_title, row_title |
Character title displayed above the columns / beside the rows of each heatmap. |
na_col |
Colour used for |
column_names_side |
Side for column names. Default
|
row_annotation |
A structured list specifying row annotations.
See |
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.
See |
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
|
links_span |
Width (in inches) of the gap column between the two heatmaps where link curves are drawn. Default 0.5. |
link_width_by |
Optional column name in |
link_width_scale |
Numeric scaling factor applied to the normalised
link intensity values to produce final line widths ( |
link_color |
Colour of the link spline curves. Default
|
link_alpha |
Alpha transparency of link curves in |
alpha |
Alpha transparency for heatmap cells in |
seed |
Random seed for reproducibility. Default 8525. |
padding |
Padding around the heatmap in CSS order (top, right, bottom, left). Supports 1–4 values. Default 15 (mm). |
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
|
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
|
A patchwork-wrapped grob (class wrap_plots) with
height and width attributes (in inches). The original
data is stored in p$data.
Parameter resolution — extra arguments passed via
... are split into left-specific and right-specific groups
by prefix (left_ vs right_). Each group is merged
with the shared defaults using %||% fallback chains,
giving the caller full per-side override capability.
Cell dimension pre-computation — the internal helper
.get_dim_pre() calculates exact cell width and height
(in "inches" units) from cell_type,
aspect.ratio, base_size, and the unique row/column
counts (including split groups). These are passed as explicit
width / height arguments to
ComplexHeatmap::Heatmap() so that cells have a guaranteed
physical size rather than using null units.
Delegation to HeatmapAtomic — both the left and
right heatmaps are created by calling
do_call(HeatmapAtomic, ...) with return_ht = TRUE.
This returns the prepared Heatmap object (with
cell_w/cell_h attributes) without drawing it.
Dimension extraction — exact component heights and widths
are read from the prepared Heatmap objects via
ComplexHeatmap:::component_height() and
ComplexHeatmap:::component_width(). These 9-element vectors
break down every part of the heatmap (title, dendrogram, names,
annotations, body) so the composite layout can be sized precisely.
Link table construction — rows in the left and right
heatmaps are matched by grouping the input data on the row
identifier columns (plus optional rows_split_by). Each
link's position is mapped to the ordered row index in its
respective heatmap (respecting clustering order).
Legend collection — legends from both heatmaps are
collected, packed via ComplexHeatmap::packLegend(), and
placed according to legend.position (left, right, top, or
bottom).
Composite drawing — a grid.layout is built
dynamically based on the legend position. Each heatmap is drawn
inside a centered, exact-size viewport so
ComplexHeatmap::draw() sizes the body to the pre-computed
row/column counts. Link lines are drawn as grid.xspline()
curves in a dedicated gap column between the two heatmaps.
Dimension attributes — the final patchwork-wrapped
grob carries height and width attributes (in inches)
for consistent rendering in downstream layouts.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.