
Group-Level Expression Heatmap with Optional Dot Overlay
GroupHeatmap.RdComputes mean expression per combination of group.by levels for the
supplied features, scales across groups (z-score by default), and
draws a ComplexHeatmap with:
Color fill = scaled mean expression
Dot overlay (optional) - dots sized by \ expressing each gene within each column group
Row split + textbox labels - rows grouped and annotated by
feature_splitcategoriesColumn faceting - each level of
column_split_byforms a panel; within every panel allgroup.bycombinations are shownColumn annotation - one color bar per
group.byvariable (analogous to ComplexHeatmap's multi-bar top annotation)
Usage
GroupHeatmap(
seurat_object,
group.by,
features,
feature_split = NULL,
feature_column = NULL,
feature_group_column = NULL,
column_split_by = NULL,
assay = "RNA",
layer = "data",
scale_method = "zscore",
add_dot = TRUE,
add_bg = TRUE,
dot_size = grid::unit(4, "mm"),
pct_cutoff = 0,
palette = "RdBu",
color_scale = NULL,
scale_limits = c(-2, 2),
group_colors = NULL,
column_split_colors = NULL,
feature_split_colors = NULL,
textbox_labels = TRUE,
cluster_rows = TRUE,
cluster_row_slices = FALSE,
cluster_columns = FALSE,
heatmap_params = list(show_row_names = TRUE, row_names_side = "right", row_names_gp =
grid::gpar(fontsize = 8), show_row_dend = FALSE, column_names_side = "top",
column_title = NULL),
auto_draw = TRUE,
legend_side = "right",
width = grid::unit(5, "in"),
height = grid::unit(7, "in"),
auto_size = TRUE,
pdf.width = NULL,
pdf.height = NULL,
output_dir = NULL,
object_name = "",
subset_name = "",
file_name = NULL,
timestamp = FALSE
)Arguments
- seurat_object
A Seurat object.
- group.by
Character vector of metadata column(s) whose unique combinations become the heatmap columns (e.g.
c("CellTypes", "Treatment")).- features
Either a character vector of gene names, or a
data.frame. When a data.frame, the gene column is taken fromfeature_columnand (if given) row groups fromfeature_group_column- so a marker table can be passed directly.- feature_split
Row-group labels. Either a named vector (names = gene symbols, values = group labels), or an unnamed vector the same length as
features(matched by position). When supplied, rows are split and labeled. Ignored whenfeaturesis a data.frame withfeature_group_columnset.- feature_column
Character or
NULL. Whenfeaturesis a data.frame, the column holding gene names.NULLauto-detects (gene/feature/Genes/...) or uses the first column.- feature_group_column
Character or
NULL. Whenfeaturesis a data.frame, the column holding row-group labels (becomesfeature_split).NULLauto-detects (group/cluster/CellType/...) if present.- column_split_by
Optional metadata column used to facet (visually split) the columns into panels. May be one of the
group.byvariables or a separate one.- assay
Assay to use. Default
"RNA".- layer
Layer for expression extraction. Default
"data".- scale_method
"zscore"(default),"minmax", or"none".- add_dot
Logical. Overlay dots sized by \
TRUE.- add_bg
Logical. Draw a white disc behind each dot so it pops against dark expression colors. Default
TRUE.- dot_size
Base dot size as a
grid::unitobject. Defaultgrid::unit(4, "mm").- pct_cutoff
Minimum fraction expressing (0-1) to draw a dot. Default
0.- palette
RColorBrewer diverging palette for the expression color scale. Default
"RdBu".- color_scale
Optional pre-built
circlize::colorRamp2object. Overridespalette.- scale_limits
c(min, max)for the color scale. Defaultc(-2, 2).- group_colors
Colors for
group.bylevels. Accepts:A named list where each element is a named color vector for one
group.byvariable, e.g.list(CellType = ct_cols, Treatment = tx_cols).A named vector when
group.byhas length 1 (backward-compatible).NULL(default) - auto-assigned from PrepObject orNour_pal.
- column_split_colors
Named color vector for
column_split_bylevels.- feature_split_colors
Named color vector for
feature_splitcategories (cosmetic; not currently used in cell_fun).- textbox_labels
Logical. Use
anno_textboxwhen available (ComplexHeatmap ≥ 2.13). DefaultTRUE.- cluster_rows
Logical. Cluster rows within each split. Default
TRUE.- cluster_row_slices
Logical. Cluster row slices. Default
FALSE.- cluster_columns
Logical. Cluster columns within each split. Default
FALSE.- heatmap_params
Named list of extra arguments forwarded to
ComplexHeatmap::Heatmap().- auto_draw
Logical. Render automatically after building. Default
TRUE.- legend_side
Where to place the legends. Default
"right". Moves both the heatmap color legend and the annotation legends (row-split modules, top annotations) to the same side.- width
Heatmap body width, as a
grid::unitor a bare numeric (interpreted as inches). When left at the default andauto_size = TRUE, the body width is derived from the number of columns. Defaultgrid::unit(5, "in").- height
Heatmap body height (
grid::unitor numeric inches). Auto-derived from the number of rows when left at the default andauto_size = TRUE. Defaultgrid::unit(7, "in").- auto_size
Logical. When
TRUE(default) andwidth/heightare not explicitly supplied, size the heatmap body from the number of genes and column groups. The saved PDF is always sized to fit the longest row and column names regardless of this setting.- pdf.width, pdf.height
Numeric. PDF device width and height in inches. When supplied, these are passed directly to
grDevices::pdf()and override all automatic size estimation. Use these when the heuristic sizing gets the device dimensions wrong (e.g. very wide heatmaps with many donors).NULL(default) keeps the automatic behavior.- output_dir
Directory to save a PDF.
NULL= no file.- object_name
Prefix for output file names. Falls back to the
object_namestored byPrepObject.- subset_name
Optional subset label inserted into the file name. Falls back to the
subset_namestored byPrepObject.- file_name
Character or
NULL. Base name (no extension) for the saved PDF.NULL(default) auto-deduces the name fromobject_name,subset_name, thefeaturesvariable name, and thegroup.by/column_split_byvariables.- timestamp
Logical. When
TRUE, append a_YYYYMMDD-HHMMSSstamp to the saved file name so repeated runs are versioned instead of overwriting the previous PDF. DefaultFALSE.
Value
Invisibly, a named list:
heatmapThe
Heatmapobject.expression_matrixScaled mean-expression matrix.
percent_matrixFraction expressing per column group.
column_groupsData frame of all column combinations.
feature_splitThe
feature_splitvector used.dot_legendThe dot-size
Legendobject orNULL.
Multiple group.by variables
group.by may be a character vector of length > 1. The heatmap
columns are the observed unique combinations of all listed
variables, ordered by the first variable, then the second, etc.
The top annotation automatically shows one color bar per variable.
column_split_by behavior
When column_split_by is supplied the function computes expression
for every (group.by × column_split_by) combination found in the
object. This means a CellType that appears in both "Vehicle" and "Drug"
produces two columns (one per treatment), placed in their
respective panels. This is the correct faceting behavior.