| Title: | Multilayer Plots for Single-Cell Data |
|---|---|
| Description: | scOverlay provides publication-grade plotting helpers to display a foreground feature (gene expression or metadata) on top of a contextual background (clusters, cell types, samples, or a solid colour) in the same reduced dimension panel, each with independent colour scales (via ggnewscale). It integrates with SingleCellExperiment / SummarizedExperiment, supports flexible subsetting of foreground cells, multiple assays (e.g. counts, logcounts), and grid arrangements by user-defined grouping columns. |
| Authors: | Bernat Gel [aut, cre] (ORCID: <https://orcid.org/0000-0001-8878-349X>) |
| Maintainer: | Bernat Gel <[email protected]> |
| License: | Artistic-2.0 |
| Version: | 0.99.5 |
| Built: | 2026-10-26 23:28:56 UTC |
| Source: | https://github.com/bioc/scOverlay |
getPalette converts a palette specification into a vector of colours
that can be used by scOverlay or directly in a ggplot2 scale.
getPalette( palette = NULL, type = c("continuous", "categorical"), n = NULL, values = NULL )getPalette( palette = NULL, type = c("continuous", "categorical"), n = NULL, values = NULL )
palette |
Palette specification. It can be |
type |
Character value indicating the type of palette to return.
Accepted values are |
n |
Number of colours to return. If |
values |
Optional character vector with the expected categorical values.
When supplied and the resolved palette is named, names are used to map colours
to values. Defaults to |
Palette specifications can be NULL, the name of one of the palettes
bundled with scOverlay, a vector of colours, or a palette function. Palette
names are first looked up in scOverlay's internal palette registry for the
requested type, then in viridisLite, and then among ColorBrewer
palettes through scales.
When palette = NULL, getPalette uses the default scOverlay
palette for the requested type: "scOverlay" for categorical palettes and
"gray_red" for continuous palettes.
Continuous palettes are represented as anchor colours and interpolated
internally to the requested number of colours. This means that a user supplied
vector such as c("gray90", "red", "darkred") can be used as a
continuous gradient.
Categorical palettes can be named. When values is supplied and all
values are present in the palette names, colours are matched by name. When no
values are present in the palette names, colours are assigned by position. If
only some values match, getPalette() raises an error to avoid silent
colour remapping. Built-in categorical palettes intentionally keep
integer-like names such as "1", "2" and "3" because
these are useful for cluster labels. Use unname() to force positional
matching for a named palette, or setNames() to assign or replace names.
If a categorical palette has fewer colours than requested, additional colours
are generated by interpolation.
The categorical palette "combinationBright" contains 32 colours and is
used by default for fg_type = "combination" foregrounds in
plotOverlay.
A character vector of colours. For categorical palettes, the returned
vector is named with values when values is supplied.
getPalette("gray_red", type = "continuous", n = 5) getPalette( palette = c("#E6E6E6", "#EF6F6C", "#67000D"), type = "continuous", n = 5 ) getPalette( palette = "scOverlay", type = "categorical", n = 3, values = c("A", "B", "C") ) getPalette("combinationBright", type = "categorical", n = 8) getPalette( palette = c(A = "red", B = "blue"), type = "categorical", values = c("B", "A") ) pal <- getPalette("scOverlay", type = "categorical", n = 4) setNames(unname(pal), c("Nerve", "PNF", "ANF", "MPNST"))getPalette("gray_red", type = "continuous", n = 5) getPalette( palette = c("#E6E6E6", "#EF6F6C", "#67000D"), type = "continuous", n = 5 ) getPalette( palette = "scOverlay", type = "categorical", n = 3, values = c("A", "B", "C") ) getPalette("combinationBright", type = "categorical", n = 8) getPalette( palette = c(A = "red", B = "blue"), type = "categorical", values = c("B", "A") ) pal <- getPalette("scOverlay", type = "categorical", n = 4) setNames(unname(pal), c("Nerve", "PNF", "ANF", "MPNST"))
listPalettes returns metadata for the palettes bundled with scOverlay.
listPalettes(type = c("all", "categorical", "continuous", "bivariate"))listPalettes(type = c("all", "categorical", "continuous", "bivariate"))
type |
Character value indicating which palettes to list. Accepted
values are |
Categorical palettes return their stored colour vectors. Internally defined
continuous palettes return their stored anchor colours. Externally generated
continuous palettes, such as viridisLite palettes, return
n = NA_integer_ and colours = NA because scOverlay does not
store a fixed colour vector for them. Bivariate palettes return their four
named corner colours: low_xy, high_x, high_y and
high_xy.
The is_default column marks the palettes used by
getPalette when palette = NULL: "scOverlay" for
categorical palettes, "gray_red" for continuous palettes and
"bivariateBright" for bivariate foregrounds.
A data.frame with palette name, type, stored
colour count n, a colours list-column containing stored palette
definitions, and a logical is_default column indicating the default
palettes.
getPalette, plotPalettes,
plotBivariateLegend and plotOverlay.
listPalettes() listPalettes(type = "bivariate") pal_info <- listPalettes(type = "bivariate") pal_info$colours[[which(pal_info$name == "bivariateBright")]] pal_info <- listPalettes(type = "continuous") pal_info$colours[[which(pal_info$name == "gray_blue")]]listPalettes() listPalettes(type = "bivariate") pal_info <- listPalettes(type = "bivariate") pal_info$colours[[which(pal_info$name == "bivariateBright")]] pal_info <- listPalettes(type = "continuous") pal_info$colours[[which(pal_info$name == "gray_blue")]]
plotBivariateLegend creates a square tile legend for bivariate
foreground palettes used by plotOverlay when
fg_type = "bivariate". It returns a standalone ggplot2 object
that can be combined manually with an overlay plot, for example with
patchwork.
plotBivariateLegend(features, palette = "bivariateBright", n_bins = 9L)plotBivariateLegend(features, palette = "bivariateBright", n_bins = 9L)
features |
Character vector of length two. The first feature labels the
x direction and maps to the |
palette |
Bivariate palette specification. It can be one of the built-in
bivariate palette names, such as |
n_bins |
Number of bins per axis in the displayed colour grid. Must be a
single integer greater than or equal to 2. Defaults to |
A ggplot2 object containing the bivariate colour grid.
data("sce_overlay_example") p <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "bivariate" ) leg <- plotBivariateLegend(c("Gene1", "Gene2")) leg patchwork::wrap_plots( p, plotBivariateLegend(features = c("Gene1", "Gene2")), widths = c(1, 0.2) ) custom_pal <- c( low_xy = "#e6e6e6", high_x = "#ff4346", high_y = "#55b2ff", high_xy = "#7a1fa2" ) plotBivariateLegend( features = c("Gene1", "Gene2"), palette = custom_pal )data("sce_overlay_example") p <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "bivariate" ) leg <- plotBivariateLegend(c("Gene1", "Gene2")) leg patchwork::wrap_plots( p, plotBivariateLegend(features = c("Gene1", "Gene2")), widths = c(1, 0.2) ) custom_pal <- c( low_xy = "#e6e6e6", high_x = "#ff4346", high_y = "#55b2ff", high_xy = "#7a1fa2" ) plotBivariateLegend( features = c("Gene1", "Gene2"), palette = custom_pal )
plotGeneOverlay creates one plotOverlay plot for each
gene in genes and returns them as a named list.
plotGeneOverlay(sce, genes, ...)plotGeneOverlay(sce, genes, ...)
sce |
A SingleCellExperiment object containing the reduced dimensions and gene expression values to plot. |
genes |
Character vector with the genes to plot. Genes are looked up in
|
... |
Additional arguments passed to |
This is a convenience function to quickly inspect the expression pattern of
several genes on the same embedding. All additional plotting arguments are
passed to plotOverlay.
Genes not present in rownames(sce) are skipped with a warning. If none
of the requested genes are found, the function stops with an error.
A named list of ggplot2 objects, one for each gene found in
rownames(sce).
plotOverlay, getPalette and
listPalettes.
data("sce_overlay_example") plots <- plotGeneOverlay( sce = sce_overlay_example, genes = c("SOX10", "S100B"), reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) plots$SOX10data("sce_overlay_example") plots <- plotGeneOverlay( sce = sce_overlay_example, genes = c("SOX10", "S100B"), reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) plots$SOX10
plotOverlay creates a layered plot of a reduced dimension
representation stored in a SingleCellExperiment object. It
first creates a background layer, dims this background with a semi-transparent
white overlay, and finally draws a foreground variable on top using an
independent colour scale. When a layer is set to "none", the
corresponding point layer is kept in the plot structure without drawing
visible points.
plotOverlay( sce, foreground, background = "solid", reduced_dim = "TSNE", fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), bg_assay = "logcounts", fg_assay = "logcounts", fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 4, fg_point_size = 1, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.9, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, title = NULL, bg_values = NULL, fg_values = NULL )plotOverlay( sce, foreground, background = "solid", reduced_dim = "TSNE", fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), bg_assay = "logcounts", fg_assay = "logcounts", fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 4, fg_point_size = 1, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.9, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, title = NULL, bg_values = NULL, fg_values = NULL )
sce |
A SingleCellExperiment object containing the reduced
dimensions and the data to plot. The object must contain the reduced
dimension specified in |
foreground |
A character value specifying the variable to draw in the
foreground layer. It can be |
background |
A single character value specifying the background layer.
It can be |
reduced_dim |
A single character value with the name of the reduced
dimension to plot. It must be one of |
fg_subset_cells |
A cell subset defining which cells are shown in the
foreground layer. It can be |
bg_type |
A character value indicating how the background variable should
be represented when |
fg_type |
A character value indicating how the foreground variable should
be represented when |
bg_assay |
A single character value with the name of the assay to use
when |
fg_assay |
A single character value with the name of the assay to use
when |
fg_threshold |
Thresholds used only when
|
fg_order |
A character value controlling the drawing order of foreground
cells. Accepted values are |
bg_point_size |
Numeric value with the point size of the background
layer. Defaults to |
fg_point_size |
Numeric value with the point size of the foreground
layer. Defaults to |
bg_palette |
Palette specification for the background layer. It is
ignored when |
fg_palette |
Palette specification for the foreground layer. It is
ignored when |
bg_raster |
Logical value. If |
fg_raster |
Logical value. If |
raster_dpi |
Positive numeric value with the resolution, in dots per
inch, used for rasterized point layers. Defaults to |
bg_dimming |
Numeric value between 0 and 1 controlling the opacity of the
white dimming layer placed between background and foreground. A value of
|
fg_limits |
Limits for the foreground colour scale when the foreground is
continuous. It can be |
bg_limits |
Limits for the background colour scale when the background is
continuous. It can be |
bg_legend |
Logical value indicating whether to show the background
legend. It is ignored when |
fg_legend |
Logical value indicating whether to show the foreground
legend. It is ignored when |
bg_legend_title |
Character value with the title of the background
legend. If |
fg_legend_title |
Character value with the title of the foreground
legend. If |
title |
Character value with the plot title. If |
bg_values |
Categorical value set for the background scale. This is used by grouped plotting helpers to keep categorical colours consistent across panels. Not intended for users. |
fg_values |
Categorical value set for the foreground scale. This is used by grouped plotting helpers to keep categorical colours consistent across panels. Not intended for users. |
This representation is useful to highlight gene expression, scores, annotations or selected groups of cells while keeping the complete embedding visible as context.
The function uses two visual layers. The background layer is used to show the
global structure of the embedding, usually coloured by a cell annotation such
as a cluster, sample or cell type. Either layer can also be set to
"none" to keep the layer position without drawing visible points. The
foreground layer is then drawn on top and can represent a fixed-colour
selection, a feature from one of the assays, typically a gene expression
value, or a variable stored in colData(sce).
The foreground can be restricted to a subset of cells using
fg_subset_cells. This only affects the foreground layer: cells not
selected by fg_subset_cells are still shown in the background. This is
the main idea of the overlay plot and allows highlighting a particular group
of cells without losing the context of the whole dataset.
The foreground colour scale is independent from the background colour scale.
Palettes can be specified by name, as a vector of colours, or as a palette
function. See getPalette and listPalettes for the
available palettes and palette handling rules. For continuous palettes, colour
vectors are used as anchors and interpolated internally.
For dense embeddings, the background and foreground point layers can be
rasterized independently with bg_raster and fg_raster. Only the
point layers are rasterized; axes, labels, legends and other plot elements
remain vector graphics.
A ggplot2 object with the background, dimming and foreground layers.
plotGeneOverlay,
plotOverlayPerGroup,
plotOverlayPerNestedGroup, getPalette and
listPalettes.
data("sce_overlay_example") # Overlay the expression of a gene on top of the cluster annotation. p1 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "cluster", foreground = "SOX10" ) p1 # Use a solid background and draw higher expression values on top. p2 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "solid", foreground = "S100B", fg_order = "ascending" ) p2 # Restrict the foreground to one sample type while keeping all cells in the # background. p3 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "UMAP", background = "cluster", foreground = "SOX10", fg_subset_cells = quote(sample_type == "ANNUBP") ) p3 # Use a custom continuous palette and rasterize the background point layer. p4 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "sample_type", foreground = "SOX10", fg_palette = c("#E6E6E6", "#EF6F6C", "#67000D"), bg_raster = TRUE ) p4 # Blend two numeric foreground features with a bivariate palette. p5 <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "bivariate", fg_palette = "bivariateBright" ) p5 # Create a separate bivariate legend. leg <- plotBivariateLegend( features = c("Gene1", "Gene2"), palette = "bivariateBright" ) leg # Call expression combinations from two numeric foreground features. p6 <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "combination", fg_threshold = 0 ) p6 # Highlight a subset with a solid foreground colour. p7 <- plotOverlay( sce_overlay_example, foreground = "solid", background = "cluster", fg_subset_cells = quote(cluster == "C1") ) p7data("sce_overlay_example") # Overlay the expression of a gene on top of the cluster annotation. p1 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "cluster", foreground = "SOX10" ) p1 # Use a solid background and draw higher expression values on top. p2 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "solid", foreground = "S100B", fg_order = "ascending" ) p2 # Restrict the foreground to one sample type while keeping all cells in the # background. p3 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "UMAP", background = "cluster", foreground = "SOX10", fg_subset_cells = quote(sample_type == "ANNUBP") ) p3 # Use a custom continuous palette and rasterize the background point layer. p4 <- plotOverlay( sce = sce_overlay_example, reduced_dim = "TSNE", background = "sample_type", foreground = "SOX10", fg_palette = c("#E6E6E6", "#EF6F6C", "#67000D"), bg_raster = TRUE ) p4 # Blend two numeric foreground features with a bivariate palette. p5 <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "bivariate", fg_palette = "bivariateBright" ) p5 # Create a separate bivariate legend. leg <- plotBivariateLegend( features = c("Gene1", "Gene2"), palette = "bivariateBright" ) leg # Call expression combinations from two numeric foreground features. p6 <- plotOverlay( sce_overlay_example, foreground = c("Gene1", "Gene2"), fg_type = "combination", fg_threshold = 0 ) p6 # Highlight a subset with a solid foreground colour. p7 <- plotOverlay( sce_overlay_example, foreground = "solid", background = "cluster", fg_subset_cells = quote(cluster == "C1") ) p7
plotOverlayPerGroup creates one plotOverlay plot for
each group defined by a column in colData(sce) and combines the plots
into a single patchwork object.
plotOverlayPerGroup( sce, group_col, foreground, background = "solid", reduced_dim = "TSNE", group_order = NULL, fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), bg_assay = "logcounts", fg_assay = "logcounts", fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 2, fg_point_size = 0.5, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.6, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, shared_legend = FALSE )plotOverlayPerGroup( sce, group_col, foreground, background = "solid", reduced_dim = "TSNE", group_order = NULL, fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), bg_assay = "logcounts", fg_assay = "logcounts", fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 2, fg_point_size = 0.5, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.6, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, shared_legend = FALSE )
sce |
A SingleCellExperiment object containing the reduced
dimensions and the data to plot. The object must contain the reduced
dimension specified in |
group_col |
A single character value with the name of the
|
foreground |
Foreground layer specification. It can be a feature name in
|
background |
A single character value specifying the background layer
passed to |
reduced_dim |
A single character value with the name of the reduced
dimension to plot. It must be one of |
group_order |
Optional character vector specifying the order in which
groups should be plotted. If |
fg_subset_cells |
An optional additional cell subset applied to the
foreground layer before splitting by group. It can be |
bg_type |
A character value indicating how the background variable should
be represented when |
bg_assay |
A single character value with the name of the assay to use
when |
fg_assay |
A single character value with the name of the assay to use
when |
fg_type |
A character value indicating how the foreground variable should
be represented when |
fg_threshold |
Thresholds used only when
|
fg_order |
A character value controlling the drawing order of foreground
cells within each panel. Accepted values are |
bg_point_size |
Numeric value with the point size of the background
layer in each panel. Defaults to |
fg_point_size |
Numeric value with the point size of the foreground
layer in each panel. Defaults to |
bg_palette |
Palette specification for the background layer. It can be
|
fg_palette |
Palette specification for the foreground layer. When
|
bg_raster |
Logical value. If |
fg_raster |
Logical value. If |
raster_dpi |
Positive numeric value with the resolution, in dots per
inch, used for rasterized point layers. Defaults to |
bg_dimming |
Numeric value between 0 and 1 controlling the opacity of the
white dimming layer placed between background and foreground in each panel. A
value of |
fg_limits |
Limits for the foreground colour scale when the foreground is
continuous. It can be |
bg_limits |
Limits for the background colour scale when the background is
continuous. It can be |
bg_legend |
Logical value indicating whether to show the background
legend in each panel. It is ignored when |
fg_legend |
Logical value indicating whether to show the foreground
legend in each panel. It is ignored when |
bg_legend_title |
Character value with the title of the background
legend. If |
fg_legend_title |
Character value with the title of the foreground
legend. If |
shared_legend |
Logical value indicating whether compatible legends
should be collected into a shared patchwork legend. Defaults to |
This function is useful to compare the same foreground variable across samples, sample types, clusters or any other cell-level annotation. Each panel keeps the full embedding as background, while the foreground layer is restricted to the cells belonging to the corresponding group.
The grouping variable is specified with group_col. For each value in
this column, plotOverlayPerGroup calls plotOverlay using
the same background, foreground, palette and plotting options. The foreground
subset for each panel is defined by the group membership and, optionally, by
the additional filter supplied with fg_subset_cells.
As in plotOverlay, subsetting only affects the foreground
layer. Unless background = "none", the background layer still shows all
cells in every panel, providing a common reference embedding across groups.
This makes it possible to compare where cells from different samples or
sample types are located in the same reduced dimension space.
With fg_limits = "shared", foreground ranges are computed after the
global fg_subset_cells filter and before splitting into groups. In
bivariate mode, separate shared ranges are computed for the two numeric
foreground variables so colours are comparable across panels. With
bg_limits = "shared", one background range is computed across all
cells. Categorical foreground and background palettes are based on global
categorical values, so colours remain consistent across panels. Named
categorical palettes are recommended when strict category-colour control is
needed.
If shared_legend = TRUE, compatible legends are collected with
patchwork. The legend can be repositioned afterwards with patchwork
syntax, for example p & ggplot2::theme(legend.position = "bottom").
If group_order is provided, panels are drawn following that order. If
it is NULL, factor levels are used when group_col is a factor;
otherwise, groups are shown in their order of appearance in the object.
A patchwork object combining one plotOverlay plot
per group. If no valid groups produce a panel, the function returns
NULL with a warning.
plotOverlay,
plotOverlayPerNestedGroup,
plotGeneOverlay, getPalette and
listPalettes.
data("sce_overlay_example") # Plot SOX10 expression separately for each sample type. p1 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample_type", reduced_dim = "TSNE", background = "solid", fg_order = "ascending" ) p1 # Use the same grouping but colour the background by cluster. p2 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "S100B", group_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) p2 # Specify an explicit group order. p3 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample_type", group_order = c("PNF", "ANNUBP", "MPNST"), reduced_dim = "TSNE", background = "solid" ) p3 # Compare expression across samples with shared foreground limits and a # collected legend. p4 <- plotOverlayPerGroup( sce = sce_overlay_example, group_col = "sample", foreground = "Gene1", background = "cluster", fg_limits = "shared", shared_legend = TRUE ) p4 # Use shared bivariate scaling across sample panels. p5 <- plotOverlayPerGroup( sce = sce_overlay_example, group_col = "sample", foreground = c("Gene1", "Gene2"), fg_type = "bivariate", fg_limits = "shared" ) p5data("sce_overlay_example") # Plot SOX10 expression separately for each sample type. p1 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample_type", reduced_dim = "TSNE", background = "solid", fg_order = "ascending" ) p1 # Use the same grouping but colour the background by cluster. p2 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "S100B", group_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) p2 # Specify an explicit group order. p3 <- plotOverlayPerGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample_type", group_order = c("PNF", "ANNUBP", "MPNST"), reduced_dim = "TSNE", background = "solid" ) p3 # Compare expression across samples with shared foreground limits and a # collected legend. p4 <- plotOverlayPerGroup( sce = sce_overlay_example, group_col = "sample", foreground = "Gene1", background = "cluster", fg_limits = "shared", shared_legend = TRUE ) p4 # Use shared bivariate scaling across sample panels. p5 <- plotOverlayPerGroup( sce = sce_overlay_example, group_col = "sample", foreground = c("Gene1", "Gene2"), fg_type = "bivariate", fg_limits = "shared" ) p5
plotOverlayPerNestedGroup creates one plotOverlay plot
for each observed combination of an inner and outer grouping variable. The
usual use case is to create per-sample overlay plots and arrange them by
sample type, condition or experimental group.
plotOverlayPerNestedGroup( sce, group_col, outer_col, foreground, background = "solid", reduced_dim = "TSNE", group_order = NULL, outer_order = NULL, layout = c("auto", "compact", "grid"), panel_titles = c("auto", "outer_inner", "inner", "none"), fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), bg_assay = "logcounts", fg_assay = "logcounts", fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 2, fg_point_size = 0.5, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.6, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, shared_legend = FALSE )plotOverlayPerNestedGroup( sce, group_col, outer_col, foreground, background = "solid", reduced_dim = "TSNE", group_order = NULL, outer_order = NULL, layout = c("auto", "compact", "grid"), panel_titles = c("auto", "outer_inner", "inner", "none"), fg_subset_cells = NULL, bg_type = c("auto", "continuous", "categorical"), bg_assay = "logcounts", fg_assay = "logcounts", fg_type = c("auto", "continuous", "categorical", "bivariate", "combination"), fg_threshold = 0, fg_order = c("auto", "input", "random", "ascending", "descending"), bg_point_size = 2, fg_point_size = 0.5, bg_palette = NULL, fg_palette = NULL, bg_raster = FALSE, fg_raster = FALSE, raster_dpi = 300, bg_dimming = 0.6, fg_limits = NULL, bg_limits = NULL, bg_legend = TRUE, fg_legend = TRUE, bg_legend_title = NULL, fg_legend_title = NULL, shared_legend = FALSE )
sce |
A SingleCellExperiment object containing the reduced
dimensions and the data to plot. The object must contain the reduced
dimension specified in |
group_col |
A single character value with the name of the
|
outer_col |
A single character value with the name of the
|
foreground |
Foreground layer specification. It can be a feature name in
|
background |
A single character value specifying the background layer
passed to |
reduced_dim |
A single character value with the name of the reduced
dimension to plot. It must be one of |
group_order |
Optional character vector specifying the order in which
inner groups should be plotted. If |
outer_order |
Optional character vector specifying the order of the outer
groups. If |
layout |
Character value controlling how nested panels are arranged.
Use |
panel_titles |
Character value controlling titles added to real nested
panels. Use |
fg_subset_cells |
An optional additional cell subset applied to the
foreground layer before splitting by group. It can be |
bg_type |
A character value indicating how the background variable should
be represented when |
bg_assay |
A single character value with the name of the assay to use
when |
fg_assay |
A single character value with the name of the assay to use
when |
fg_type |
A character value indicating how the foreground variable should
be represented when |
fg_threshold |
Thresholds used only when
|
fg_order |
A character value controlling the drawing order of foreground
cells within each panel. Accepted values are |
bg_point_size |
Numeric value with the point size of the background
layer in each panel. Defaults to |
fg_point_size |
Numeric value with the point size of the foreground
layer in each panel. Defaults to |
bg_palette |
Palette specification for the background layer. It can be
|
fg_palette |
Palette specification for the foreground layer. When
|
bg_raster |
Logical value. If |
fg_raster |
Logical value. If |
raster_dpi |
Positive numeric value with the resolution, in dots per
inch, used for rasterized point layers. Defaults to |
bg_dimming |
Numeric value between 0 and 1 controlling the opacity of the
white dimming layer placed between background and foreground in each panel. A
value of |
fg_limits |
Limits for the foreground colour scale when the foreground is
continuous. It can be |
bg_limits |
Limits for the background colour scale when the background is
continuous. It can be |
bg_legend |
Logical value indicating whether to show the background
legend in each panel. It is ignored when |
fg_legend |
Logical value indicating whether to show the foreground
legend in each panel. It is ignored when |
bg_legend_title |
Character value with the title of the background
legend. If |
fg_legend_title |
Character value with the title of the foreground
legend. If |
shared_legend |
Logical value indicating whether compatible legends
should be collected into a shared patchwork legend. Defaults to |
This function is useful when the cells belong to two related annotations, for example samples nested within sample types. Each panel uses all cells for the background and restricts only the foreground to one observed outer/inner group combination, with an optional additional foreground subset applied inside that panel.
The inner grouping variable is specified with group_col and the outer
grouping variable is specified with outer_col. Panels are defined by
observed outer_col and group_col combinations, then arranged
with one row per outer value. Compact layout shows only observed inner groups
within each outer row, then right-pads shorter rows with blank spacers so
panel widths remain consistent. It is useful for true nested structures, such
as sample type/sample. Grid layout reserves a full outer-by-inner grid and is
useful for repeated inner labels, such as sample type/treatment. With
layout = "auto", grid layout is used when any inner label appears in
more than one outer value; otherwise compact layout is used. Missing
combinations in grid layout are blank spacers, not background-only panels.
Existing combinations with no foreground-selected cells are still drawn using
the existing no-foreground behavior.
For each observed outer/inner combination, plotOverlayPerNestedGroup calls
plotOverlay using the same background, foreground, palette and
plotting options. The full sce is used in every panel so the
background layer always shows the full dataset. The foreground subset for
each panel is defined by the inner and outer group membership and, optionally,
by the additional filter supplied with fg_subset_cells.
Panel titles are added only to real data panels; blank spacer panels do not
receive titles.
Missing outer/inner combinations are skipped in compact layout and represented
by blank spacers in grid layout. They are not drawn as background-only panels.
When a combination exists but fg_subset_cells selects no foreground
cells, the panel is still drawn and plotOverlay handles the
empty foreground layer in the usual way.
With fg_limits = "shared", foreground ranges are computed after the
global fg_subset_cells filter and before splitting into panels. In
bivariate mode, separate shared ranges are computed for the two numeric
foreground variables so colours are comparable across panels. With
bg_limits = "shared", one background range is computed across all
cells. Categorical foreground and background palettes are based on global
categorical values, so colours remain consistent across panels. Named
categorical palettes are recommended when strict category-colour control is
needed.
If shared_legend = TRUE, compatible legends are collected with
patchwork. The legend can be repositioned afterwards with patchwork
syntax, for example p & ggplot2::theme(legend.position = "bottom").
The function supports both uniquely nested inner groups and repeated inner
labels. For uniquely nested inner groups, such as samples within sample
types, layout = "auto" resolves to "compact". For repeated
inner labels, such as treatments or QC groups present across multiple outer
groups, layout = "auto" resolves to "grid".
If group_order or outer_order are provided, panels and rows are
drawn following those orders. If they are NULL, factor levels are used
when the corresponding grouping variable is a factor; otherwise, values are
shown in their order of appearance in the object.
A patchwork object arranging one plotOverlay plot
per inner group and outer group. If no valid plots can be generated, the
function returns NULL with a warning.
plotOverlay,
plotOverlayPerGroup,
plotGeneOverlay, getPalette and
listPalettes.
data("sce_overlay_example") # Plot SOX10 expression by sample, arranging samples by sample type. p1 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "solid", fg_order = "ascending" ) p1 # Use the cluster annotation as background in every panel. p2 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "S100B", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) p2 # Specify explicit orders for rows and panels. p3 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample", outer_col = "sample_type", group_order = c("S1", "S2", "S3", "S4", "S5", "S6"), outer_order = c("PNF", "ANNUBP", "MPNST"), reduced_dim = "TSNE", background = "solid", layout = "auto" ) p3 sce_overlay_example$cluster_group <- ifelse( sce_overlay_example$cluster %in% c("C1", "C2"), "Cluster C1/C2", "Other clusters" ) p_grid <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "Gene1", group_col = "cluster_group", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_limits = "shared", shared_legend = TRUE, layout = "auto" ) p_grid # Reuse one foreground scale and collect compatible legends. p4 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "Gene1", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_limits = "shared", shared_legend = TRUE ) p4data("sce_overlay_example") # Plot SOX10 expression by sample, arranging samples by sample type. p1 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "solid", fg_order = "ascending" ) p1 # Use the cluster annotation as background in every panel. p2 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "S100B", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_order = "ascending" ) p2 # Specify explicit orders for rows and panels. p3 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "SOX10", group_col = "sample", outer_col = "sample_type", group_order = c("S1", "S2", "S3", "S4", "S5", "S6"), outer_order = c("PNF", "ANNUBP", "MPNST"), reduced_dim = "TSNE", background = "solid", layout = "auto" ) p3 sce_overlay_example$cluster_group <- ifelse( sce_overlay_example$cluster %in% c("C1", "C2"), "Cluster C1/C2", "Other clusters" ) p_grid <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "Gene1", group_col = "cluster_group", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_limits = "shared", shared_legend = TRUE, layout = "auto" ) p_grid # Reuse one foreground scale and collect compatible legends. p4 <- plotOverlayPerNestedGroup( sce = sce_overlay_example, foreground = "Gene1", group_col = "sample", outer_col = "sample_type", reduced_dim = "TSNE", background = "cluster", fg_limits = "shared", shared_legend = TRUE ) p4
plotPalettes displays the palettes bundled with scOverlay. Categorical
and continuous palettes are displayed as one-dimensional swatches. Bivariate
palettes are displayed as two-dimensional colour grids using the same
orientation as plotBivariateLegend: feature 1 increases from
left to right and feature 2 increases from bottom to top.
plotPalettes( type = c("all", "categorical", "continuous", "bivariate"), n = 24, show_names = TRUE )plotPalettes( type = c("all", "categorical", "continuous", "bivariate"), n = 24, show_names = TRUE )
type |
Character value indicating which palettes to display. Accepted
values are |
n |
Number of colours used to display continuous palettes, the maximum
number of colours shown for categorical palettes, and the number of bins per
axis for bivariate palettes. Non-integer values are truncated with
|
show_names |
Logical value. If |
Continuous palettes may be sampled or interpolated for display, including
externally generated palettes such as viridisLite palettes. Use
listPalettes to inspect, copy or modify stored palette
definitions.
A ggplot2 object for a single preview section or a patchwork object when multiple sections are shown.
listPalettes, plotBivariateLegend and
getPalette.
plotPalettes() plotPalettes(type = "continuous") plotPalettes(type = "bivariate")plotPalettes() plotPalettes(type = "continuous") plotPalettes(type = "bivariate")
A reduced SingleCellExperiment derived from a single-cell study of peripheral nerve and NF1-associated tumours generated by the package author's research group. The originating study was deposited at the European Genome-phenome Archive (EGAS50000001747).
A SingleCellExperiment with a
selected set of log-normalized expression values in the logcounts
assay (not raw counts), cell metadata (including sample type, cell types and
quality-control metrics), and two-dimensional TSNE coordinates.
UMAP and PCA coordinates are retained when available in the
processed source object.
The example was extracted from an independently processed
SingleCellExperiment; the upstream single-cell preprocessing pipeline
is not part of scOverlay. Two nerve, two PNF, two ANF and three MPNST samples
were selected, with up to 2,500 cells sampled from each. A subset of genes,
annotations and embedding coordinates was retained. Original sample IDs were
replaced with generic labels (e.g., Nerve1, PNF1, ANF1,
MPNST1), including the sample prefixes of cell identifiers. No direct
patient identifiers are included.
The reduced example data are distributed with scOverlay under the Artistic-2.0 license. This applies to the reduced packaged example and does not change the access conditions of the original EGA study.
Generated by the package author's research group; originating study deposited at the European Genome-phenome Archive, accession EGAS50000001747, https://ega-archive.org/studies/EGAS50000001747.
data("sce_mpnst_example") sce_mpnst_exampledata("sce_mpnst_example") sce_mpnst_example
A small SingleCellExperiment object used in scOverlay examples
and tests. It contains a small synthetic set of cells, genes, cell
annotations and reduced dimensions to demonstrate the plotting functions
quickly.
It includes logcounts, TSNE and UMAP reduced dimensions,
and cell metadata such as sample, sample_type and
cluster.
A SingleCellExperiment object with gene expression values, cell metadata and reduced dimensions.
data("sce_overlay_example") sce_overlay_exampledata("sce_overlay_example") sce_overlay_example