| Title: | Plotting functions for bixverse |
|---|---|
| Description: | This package contains various plotting helpers for the core functions of the bixverse package. |
| Authors: | Gregor Lueg [aut, cre], Liesbeth François [aut] |
| Maintainer: | Gregor Lueg <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.9 |
| Built: | 2026-10-14 23:54:48 UTC |
| Source: | https://github.com/GregorLueg/bixverse.plots |
Requires grouped data; outlier groups are read from per_group_stats.
## S3 method for class 'CellQc' density_plot_sc(x, adjust_position_label = 0, palette = BX_PALETTES, ...)## S3 method for class 'CellQc' density_plot_sc(x, adjust_position_label = 0, palette = BX_PALETTES, ...)
x |
A |
adjust_position_label |
Numeric. x-offset for the labels (default: 0). |
palette |
String. Discrete palette for the group fills and labels. One
of |
... |
Ignored. |
A named list of ggplot objects, one per metric.
Group-level outliers are recomputed from per-group medians.
## S3 method for class 'data.table' density_plot_sc( x, grouping_column, variable, direction = c("twosided", "below", "above"), threshold = 3, var_name = NULL, log_scale = TRUE, adjust_position_label = 0, palette = BX_PALETTES, ... )## S3 method for class 'data.table' density_plot_sc( x, grouping_column, variable, direction = c("twosided", "below", "above"), threshold = 3, var_name = NULL, log_scale = TRUE, adjust_position_label = 0, palette = BX_PALETTES, ... )
x |
data.table. Input data containing the QC metric. |
grouping_column |
Character. Column used to group the densities. |
variable |
Character. Numeric column to plot on the x-axis. |
direction |
Character. One of |
threshold |
Numeric. Number of MADs for outlier detection (default: 3). |
var_name |
Character. x-axis label (default: NULL). |
log_scale |
Logical. Apply a log10 x-axis (default: TRUE). |
adjust_position_label |
Numeric. x-offset for the labels (default: 0). |
palette |
String. Discrete palette for the group fills and labels. One
of |
... |
Ignored. |
A ggplot object.
Dot plot of marker gene expression across groups
dot_plot_sc( object, features, grouping_variable, feature_labels = NULL, feature_grouping = NULL, scale_exp = TRUE, modality = c("rna", "adt"), cluster_groups = TRUE, palette = c("sequential", "spectral", "viridis", "diverging") )dot_plot_sc( object, features, grouping_variable, feature_labels = NULL, feature_grouping = NULL, scale_exp = TRUE, modality = c("rna", "adt"), cluster_groups = TRUE, palette = c("sequential", "spectral", "viridis", "diverging") )
object |
A single cell class. |
features |
Character vector. Gene IDs to plot. |
grouping_variable |
String. Obs column to group by. |
feature_labels |
Optional named character vector mapping gene ids to display labels (default: NULL). |
feature_grouping |
Optional named character vector mapping gene ids to grouping labels, e.g. cell type labels. If feature_labels is provided, the character vectors should contain the mapping of feature display labels to their respecitve groups (e.g. c(CD3E = "T cell", CD8A = "T cell", MS4A1 = "B cell", ...). (default: NULL). |
scale_exp |
Boolean. Whether to min-max scale mean expression per gene. |
modality |
String. One of |
cluster_groups |
Boolean. Use hierarchical clustering on the grouping variable to re-order the group labels based on expression similarity. |
palette |
String. Continuous palette for the scaled expression. One of
|
A ggplot object.
Embedding plot coloured by an obs column
embedding_plot_sc( object, embedding, colour_by, label_by = NULL, discrete = NULL, embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), palette = NULL, label_size = 3, label_color = "black", label_font = "bold" )embedding_plot_sc( object, embedding, colour_by, label_by = NULL, discrete = NULL, embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), palette = NULL, label_size = 3, label_color = "black", label_font = "bold" )
object |
A single cell class. |
embedding |
String. Name of the embedding (e.g. |
colour_by |
String. Obs column to colour by. |
label_by |
String. Optional obs column to label by. (default: NULL). |
discrete |
Optional boolean. Force a discrete scale by coercing
|
embd_modality |
String. Modality the embedding is pulled from. One of
|
point_size |
Optional numeric. Defines the point size. If not provided, will be auto-determined. |
point_alpha |
Numeric. Defines the alpha. |
raster |
Optional boolean. Shall the plot be rasterised. If |
raster_dpi |
Two numerics. Pixel resolution for rasterized plots, passed
to geom_scattermore(). Default is |
palette |
Optional string. Palette for the colour scale, see
|
label_size |
Numeric. Size of the labels |
label_color |
String. Color fo the labels. |
label_font |
String. Font of the labels.
|
A ggplot object.
Helper function to generate an enrichment map based on GSEA results. Similar enriched gene sets are clustered together via their Jaccard similarity (alternatively overlap coefficient) and the function returns an igraph object for subsequent visualisations.
enrichment_map_gsea( res, threshold, pathways, overlap_coefficient = FALSE, min_sim = 0.2, resolution = 1, layout_func = igraph::layout_with_fr, ... )enrichment_map_gsea( res, threshold, pathways, overlap_coefficient = FALSE, min_sim = 0.2, resolution = 1, layout_func = igraph::layout_with_fr, ... )
res |
data.table with the enrichment results. Needs to have the columns
|
threshold |
Numeric. The FDR threshold you wish to filter for. |
pathways |
Named list. The original pathway list used for the calculation of the overenrichment analysis. |
overlap_coefficient |
Boolean. Shall the overlap coefficient be used instead of the Jaccard similarity. |
min_sim |
Numeric. Minimum similarity between two gene sets to be connected. |
resolution |
Numeric. The resolution parameter for the Louvain clustering. |
layout_func |
Layout function. Please see |
... |
Further parameters to forward to
|
igraph object representing the enrichment map.
Helper function to generate an enrichment map based on overenrichment results. Similar enriched gene sets are clustered together via their Jaccard similarity (alternatively overlap coefficient) and the function returns an igraph object for subsequent visualisations.
enrichment_map_oae( res, threshold, pathways, overlap_coefficient = FALSE, min_sim = 0.2, resolution = 1, layout_func = igraph::layout_with_fr, ... )enrichment_map_oae( res, threshold, pathways, overlap_coefficient = FALSE, min_sim = 0.2, resolution = 1, layout_func = igraph::layout_with_fr, ... )
res |
data.table with the enrichment results. Needs to have the columns
|
threshold |
Numeric. The FDR threshold you wish to filter for. |
pathways |
Named list. The original pathway list used for the calculation of the overenrichment analysis. |
overlap_coefficient |
Boolean. Shall the overlap coefficient be used instead of the Jaccard similarity. |
min_sim |
Numeric. Minimum similarity between two gene sets to be connected. |
resolution |
Numeric. The resolution parameter for the Louvain clustering. |
layout_func |
Layout function. Please see |
... |
Further parameters to forward to
|
igraph object representing the enrichment map.
Plots the expression of one or more features over an embedding. By default
every feature gets its own panel and its own colour bar
(scale_mode = "free"), so a weakly expressed gene is not flattened by
whatever the loudest gene in the set happens to be. Use
scale_mode = "shared" for a single faceted plot with one colour bar across
all features.
feature_plot_sc( object, features, embedding, feature_labels = NULL, scale = FALSE, clip = NULL, expr_modality = c("rna", "adt"), embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), label_by = NULL, label_size = 3, label_color = "black", label_font = "bold", highlight_features = FALSE, highlight_quantile = 0.25, scale_mode = c("free", "shared"), palette = c("sequential", "spectral", "viridis", "diverging"), ncol = NULL, ... )feature_plot_sc( object, features, embedding, feature_labels = NULL, scale = FALSE, clip = NULL, expr_modality = c("rna", "adt"), embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), label_by = NULL, label_size = 3, label_color = "black", label_font = "bold", highlight_features = FALSE, highlight_quantile = 0.25, scale_mode = c("free", "shared"), palette = c("sequential", "spectral", "viridis", "diverging"), ncol = NULL, ... )
object |
A single cell class. |
features |
Character vector. Gene/feature IDs to plot, taken from
|
embedding |
String. Name of the embedding. |
feature_labels |
Optional named character vector mapping gene ids to display labels (default: NULL). |
scale |
Boolean. Whether to z-score the expression values. |
clip |
Optional numeric. Clip z-scores if |
expr_modality |
String. Modality the expression is pulled from. One of
|
embd_modality |
String. Modality the embedding is pulled from. One of
|
point_size |
Optional numeric. Defines the point size. If not provided, will be auto-determined. |
point_alpha |
Numeric. Defines the alpha. |
raster |
Optional boolean. Shall the plot be rasterised. If |
raster_dpi |
Two numerics. Pixel resolution for rasterized plots, passed
to geom_scattermore(). Default is |
label_by |
String. Optional obs column to label by. (default: NULL). |
label_size |
Numeric. Size of the labels |
label_color |
String. Color fo the labels. |
label_font |
String. Font of the labels. |
highlight_features |
Boolean. Shall the features be more strongly highlighted. Useful for sparsely expressed genes. |
highlight_quantile |
Numeric between |
scale_mode |
String. One of |
palette |
String. Continuous palette for the expression values. One of
|
ncol |
Optional integer. Number of columns of the panel grid. Only has
an effect if |
... |
Additional arguments forwarded to
|
A patchwork object if
scale_mode = "free", otherwise a ggplot object.
Plots two features against each other (typical use case: protein vs mRNA
on ADT/RNA data). Each feature may carry a _rna or _adt suffix to
select its modality independently; unsuffixed features fall back to
modality. With geom = "density" points are coloured by 2D KDE, with
geom = "hex" cells are binned into hexagons.
feature_scatter_plot_sc( object, feature_1, feature_2, geom = c("density", "hex"), remove_zeros = TRUE, smoothness = 10, bins = 60, modality = c("rna", "adt"), point_size = 2.5, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), palette = c("viridis", "sequential", "spectral", "diverging") )feature_scatter_plot_sc( object, feature_1, feature_2, geom = c("density", "hex"), remove_zeros = TRUE, smoothness = 10, bins = 60, modality = c("rna", "adt"), point_size = 2.5, point_alpha = 0.5, raster = NULL, raster_dpi = c(512, 512), palette = c("viridis", "sequential", "spectral", "diverging") )
object |
A single cell class. |
feature_1 |
String. First feature (x-axis), optionally |
feature_2 |
String. Second feature (y-axis), optionally |
geom |
String. |
remove_zeros |
Boolean. Drop cells where both features are zero (default: TRUE). |
smoothness |
Numeric. Bandwidth multiplier for the KDE (default: 10).
Only used for |
bins |
Numeric. Number of hex bins (default: 60). Only used for
|
modality |
String. Fallback modality for unsuffixed features. One
of |
point_size |
Numeric. Point size for density plots (default: 2.5). |
point_alpha |
Numeric. Alpha for density plots (default: 0.5). |
raster |
Optional boolean. Shall the plot be rasterised. If |
raster_dpi |
Two numerics. Pixel resolution for rasterised plots
(default: |
palette |
String. Continuous palette for the density / count scale. One
of |
A ggplot object.
Helper function to get the plot data for GSEA plots
get_gsea_enrichment_data( stats, pathways, pathways_of_interest, gsea_results = NULL, gsea_param = 1 )get_gsea_enrichment_data( stats, pathways, pathways_of_interest, gsea_results = NULL, gsea_param = 1 )
stats |
Named numeric vector. The gene level statistic. |
pathways |
List. A named list with each element containing the genes for this pathway. |
pathways_of_interest |
String vector. Names of the pathways to plot. These strings need to be represented in the names of pathways. |
gsea_results |
Optional data.table with the bixverse GSEA results. If provided, the FDR and NES for the given pathway of interest will be also added to the plot. |
gsea_param |
Numeric. Defaults to |
A named list of gsea_par_plot_data objects, one per pathway that
survived the size filters. Each one is a list with the following elements:
curve_dt - data.table with the running enrichment score, columns
rank and ES.
ticks_dt - data.table with the positions of the pathway genes,
columns rank and stat.
stats_dt - data.table with the ranked statistic, columns rank and
stat.
key_points - Named numeric with pos_es, neg_es and spread_es,
plus nes and fdr if gsea_results was provided.
additional_label - String or NULL. The NES/FDR annotation.
The classic marker heatmap to show which cluster is what: genes as rows,
cells as columns, cells grouped by grouping_variable with white gaps and a
colour strip per group. With feature_grouping the genes get grouped per
cell type, too. Every block of cell group x gene group is drawn as one
raster, not one tile per cell.
PDF viewers tend to smooth embedded rasters. If the blocks look blurry in a PDF, save as PNG instead.
heatmap_plot_sc( object, features, grouping_variable, feature_labels = NULL, feature_grouping = NULL, scale = TRUE, clip = 2.5, modality = c("rna", "adt"), max_cells_per_group = NULL, seed = 42L, group_gap = 0.002, show_feature_labels = NULL, palette = c("diverging", "spectral", "viridis", "sequential") )heatmap_plot_sc( object, features, grouping_variable, feature_labels = NULL, feature_grouping = NULL, scale = TRUE, clip = 2.5, modality = c("rna", "adt"), max_cells_per_group = NULL, seed = 42L, group_gap = 0.002, show_feature_labels = NULL, palette = c("diverging", "spectral", "viridis", "sequential") )
object |
A single cell class. |
features |
Character vector. Gene IDs to plot, one row each, in this order. |
grouping_variable |
String. Obs column to group the cells by. Factor levels set the group order. |
feature_labels |
Optional named character vector mapping gene ids to display labels (default: NULL). |
feature_grouping |
Optional named character vector mapping gene ids to grouping labels, e.g. cell type labels. If feature_labels is provided, the character vectors should contain the mapping of feature display labels to their respective groups (e.g. c(CD3E = "T cell", CD8A = "T cell", MS4A1 = "B cell", ...). Groups are ordered by first appearance. (default: NULL). |
scale |
Boolean. Whether to z-score the expression values per gene. |
clip |
Optional numeric. Clip z-scores if |
modality |
String. One of |
max_cells_per_group |
Optional integer. Subsample every group to at
most this many cells. |
seed |
Integer. Seed for the subsampling. |
group_gap |
Numeric between |
show_feature_labels |
Optional boolean. Shall the gene names be shown.
|
palette |
String. Continuous palette for the expression values. One of
|
A ggplot object.
Joint QC plot from a CellQc object
## S3 method for class 'CellQc' joint_plot_sc( x, library_size = "log10_lib_size", nb_features = "log10_nnz", palette = c("sequential", "spectral", "viridis", "diverging"), ... )## S3 method for class 'CellQc' joint_plot_sc( x, library_size = "log10_lib_size", nb_features = "log10_nnz", palette = c("sequential", "spectral", "viridis", "diverging"), ... )
x |
A |
library_size |
Character. Column with the library size per cell. |
nb_features |
Character. Column with the number of features per cell. |
palette |
String. Continuous palette for the hexbin fill. One of
|
... |
Ignored. |
A ggExtraPlot object.
Joint QC plot from a data.table
## S3 method for class 'data.table' joint_plot_sc( x, library_size = "lib_size", nb_features = "nnz", log_scale = FALSE, palette = c("sequential", "spectral", "viridis", "diverging"), ... )## S3 method for class 'data.table' joint_plot_sc( x, library_size = "lib_size", nb_features = "nnz", log_scale = FALSE, palette = c("sequential", "spectral", "viridis", "diverging"), ... )
x |
data.table. Input data containing the QC metrics. |
library_size |
Character. Column with the library size per cell. |
nb_features |
Character. Column with the number of features per cell. |
log_scale |
Logical. Log10-transform both axes (default: FALSE). |
palette |
String. Continuous palette for the hexbin fill. One of
|
... |
Ignored. |
A ggExtraPlot object.
Adds boxed text labels at the centroid position of each group in a scatter plot. Computes group centroids with data.table for efficient summarisation. Useful for labelling cluster centres in embedding or dimensionality reduction plots (UMAP, t-SNE, PCA).
label_centroids( data = NULL, label_by, colour = "black", fill = "white", alpha = 0.5, label.size = 0, size = 4, fontface = "bold", ... )label_centroids( data = NULL, label_by, colour = "black", fill = "white", alpha = 0.5, label.size = 0, size = 4, fontface = "bold", ... )
data |
A |
label_by |
Character. Name of the (discrete) column to group and label by. |
colour |
Text colour. Default: |
fill |
Box fill colour. Default: |
alpha |
Box fill transparency in |
label.size |
Box border line width in mm. Set to |
size |
Text size in mm. Default: |
fontface |
Font face. Default: |
... |
Additional arguments passed to |
A ggplot layer.
## Not run: embedding_plot_sc( object = sc_object, embedding = "umap", colour_by = "donor_id" ) + label_centroids(label_by = "donor_id") ## End(Not run)## Not run: embedding_plot_sc( object = sc_object, embedding = "umap", colour_by = "donor_id" ) + label_centroids(label_by = "donor_id") ## End(Not run)
The Milo neighbourhood graph figure: every tested neighbourhood sits at its
index cell in an embedding, sized by its cell count and connected to the
neighbourhoods it shares cells with. With colour_by = "logFC" the
significant neighbourhoods are filled by their logFC and drawn on top,
strongest last, while the rest stay white underneath.
milo_nhood_plot_sc( object, milo_res, embedding = "umap", alpha = 0.1, overlap = 1L, colour_by = c("logFC", "majority_celltype"), show_cells = TRUE, embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.4, raster = NULL, raster_dpi = c(512, 512), cell_colour = "grey90", edge_colour = "grey50", edge_width = c(0.1, 1.5), size_range = c(0.5, 4), palette = NULL )milo_nhood_plot_sc( object, milo_res, embedding = "umap", alpha = 0.1, overlap = 1L, colour_by = c("logFC", "majority_celltype"), show_cells = TRUE, embd_modality = c("rna", "adt", "wnn"), point_size = NULL, point_alpha = 0.4, raster = NULL, raster_dpi = c(512, 512), cell_colour = "grey90", edge_colour = "grey50", edge_width = c(0.1, 1.5), size_range = c(0.5, 4), palette = NULL )
object |
A single cell class. The one the miloR result was built on. |
milo_res |
|
embedding |
String. Name of the embedding to position the nodes in. |
alpha |
Numeric. Spatial FDR threshold for a neighbourhood to count as significant (default: 0.1). |
overlap |
Integer. Minimum number of shared cells for an edge (default: 1L). |
colour_by |
String. One of |
show_cells |
Boolean. Draw the cells underneath the graph (default: TRUE). |
embd_modality |
String. One of |
point_size |
Optional numeric. Size of the cells. If not provided, will be auto-determined. |
point_alpha |
Numeric. Alpha of the cells (default: 0.4). |
raster |
Optional boolean. Shall the cell layer be rasterised. If |
raster_dpi |
Two numerics. Pixel resolution for rasterized plots, passed
to geom_scattermore(). Default is |
cell_colour |
String. Colour of the cell layer (default: "grey90"). |
edge_colour |
String. Colour of the edges (default: "grey50"). |
edge_width |
Two numerics. Range the edge widths are scaled into
(default: |
size_range |
Two numerics. Range the node sizes are scaled into
(default: |
palette |
Optional string. Palette for the nodes, see |
A ggplot object.
Dann, et al., Nat Biotechnol, 2022.
Draws the PAGA graph with every cluster sitting at the centroid of its cells in an embedding, over a faint scatter of the cells themselves. A free layout of the abstracted graph puts the nodes somewhere arbitrary, which the reader then has to relate back to the embedding by hand. This does not.
The abstracted graph is close to complete on real data, so threshold is
doing real work and dropping it to zero gives a hairball. tree_only is the
shortcut to the backbone.
paga_plot_sc( object, paga_res, embedding = "umap", threshold = 0.01, tree_only = FALSE, node_colour_by = NULL, show_cells = TRUE, label = TRUE, embd_modality = c("rna", "adt", "wnn"), centroid = c("median", "mean"), point_size = NULL, point_alpha = 0.4, raster = NULL, raster_dpi = c(512, 512), cell_colour = "grey80", edge_colour = "grey40", edge_width = c(0.2, 3), max_node_size = 12, palette = NULL, label_size = 3, label_color = "black", label_font = "bold" )paga_plot_sc( object, paga_res, embedding = "umap", threshold = 0.01, tree_only = FALSE, node_colour_by = NULL, show_cells = TRUE, label = TRUE, embd_modality = c("rna", "adt", "wnn"), centroid = c("median", "mean"), point_size = NULL, point_alpha = 0.4, raster = NULL, raster_dpi = c(512, 512), cell_colour = "grey80", edge_colour = "grey40", edge_width = c(0.2, 3), max_node_size = 12, palette = NULL, label_size = 3, label_color = "black", label_font = "bold" )
object |
A single cell class. |
paga_res |
|
embedding |
String. Name of the embedding to position the nodes in. |
threshold |
Numeric. Edges below this connectivity are dropped (default: 0.01). |
tree_only |
Boolean. Draw the maximum spanning forest rather than the full abstracted graph (default: FALSE). |
node_colour_by |
Optional string. A numeric obs column summarised per
cluster, e.g. |
show_cells |
Boolean. Draw the cells underneath the graph (default: TRUE). |
label |
Boolean. Label the nodes with their cluster (default: TRUE). |
embd_modality |
String. One of |
centroid |
String. One of |
point_size |
Optional numeric. Size of the cells. If not provided, will be auto-determined. |
point_alpha |
Numeric. Alpha of the cells (default: 0.4). |
raster |
Optional boolean. Shall the cell layer be rasterised. If |
raster_dpi |
Two numerics. Pixel resolution for rasterized plots, passed
to geom_scattermore(). Default is |
cell_colour |
String. Colour of the cell layer (default: "grey80"). |
edge_colour |
String. Colour of the edges (default: "grey40"). |
edge_width |
Two numerics. Range the edge widths are scaled into
(default: |
max_node_size |
Numeric. Size of the largest node. Node area tracks the cell count, which is what people read off it (default: 12). |
palette |
Optional string. Palette for the nodes, see |
label_size |
Numeric. Size of the labels. |
label_color |
String. Colour of the labels. |
label_font |
String. Font of the labels. |
A ggplot object.
Wolf, et al., Genome Biol., 2019.
Wrapper function for standard plot parameters
params_plots( width = 5, height = 5, file_type = c(".png", ".pdf"), unit = c("in", "px", "cm"), res = 450L, create_dir = TRUE )params_plots( width = 5, height = 5, file_type = c(".png", ".pdf"), unit = c("in", "px", "cm"), res = 450L, create_dir = TRUE )
width |
Numeric. Width of the plot. Defaults to |
height |
Numeric. Height of the plot. Defaults to |
file_type |
String. Plot type to save. Might be expanded to other file
types. One of |
unit |
String. Unit type for |
res |
Integer. Resolution for PNGs. Defaults to |
create_dir |
Boolean. Shall the plot directory be generated recursively.
Defaults to |
A named list with the following elements:
width - Numeric. Width of the plot. Defaults to 5.0.
height - Numeric. Height of the plot. Defaults to 5.0.
file_type - String. Plot type to save. Might be expanded to other file
types. One of c(".png", ".pdf"). Defaults to ".png".
unit - String. Unit type for width and height. One of c("in", "px", "cm"). Defaults to "in".
res - Integer. Resolution for PNGs. Defaults to 450L.
create_dir - Boolean. Shall the plot directory be generated
recursively. Defaults to TRUE.
Wrapper function for volcano plot parameters
params_volcano( x_axis = "log2FC", y_axis = "FDR", colour = NULL, label_column = NULL, top_features_to_label = NULL )params_volcano( x_axis = "log2FC", y_axis = "FDR", colour = NULL, label_column = NULL, top_features_to_label = NULL )
x_axis |
String. Column holding the effect size (e.g. |
y_axis |
String. Column holding the raw significance values (e.g.
|
colour |
String or |
label_column |
String or |
top_features_to_label |
Integer or |
A named list with the following elements:
x_axis - String. Column holding the effect size (e.g. "log2FC").
Defaults to "log2FC".
y_axis - String. Column holding the raw significance values (e.g.
"FDR", "fdr", "q_value"). The function applies -log10() internally.
Defaults to "FDR".
colour - String or NULL. Column to colour points by (continuous
gradient). If NULL, points are coloured by x_axis. Defaults to NULL.
label_column - String or NULL. Column holding feature labels.
Required if top_features_to_label is set. Defaults to NULL.
top_features_to_label - Integer or NULL. Number of features to
label, ranked by y_axis ascending (most significant first). Defaults to
NULL.
Draws a samples x features on/off matrix in the style of the SCENIC paper:
features as rows, samples as columns, black for on and white for off. Every
block of sample group x feature group is drawn as one raster, so the plot
stays light no matter how many samples there are, and the blocks are
separated by white gaps. Groups get a thin colour strip with their labels
written next to it. Sample and feature groups share one colour mapping, so a
feature group with the same name as a sample group gets the same colour.
group_annotation adds a second strip with a legend between the matrix and
the sample group strip, e.g. the response group of each cell line.
Filtering, ordering and binning happen in
bixverse::extract_binary_heatmap_data(). If the samples were binned the
cells show the fraction of samples on as a grey ramp.
PDF viewers tend to smooth embedded rasters. If the blocks look blurry in a PDF, save as PNG instead.
plot_binary_heatmap( x, sample_groups = NULL, feature_groups = NULL, heatmap_params = bixverse::params_binary_heatmap(), show_feature_labels = NULL, group_gap = 0.001, group_annotation = NULL, annotation_colours = NULL, palette = c("main", "sequential", "diverging", "viridis", "spectral"), .verbose = FALSE )plot_binary_heatmap( x, sample_groups = NULL, feature_groups = NULL, heatmap_params = bixverse::params_binary_heatmap(), show_feature_labels = NULL, group_gap = 0.001, group_annotation = NULL, annotation_colours = NULL, palette = c("main", "sequential", "diverging", "viridis", "spectral"), .verbose = FALSE )
x |
Either a |
sample_groups |
Optional named character vector or factor mapping
samples to groups. Only used if |
feature_groups |
Optional named character vector or factor mapping
features to groups. Only used if |
heatmap_params |
List. Output of |
show_feature_labels |
Optional boolean. Shall the feature names be
shown. |
group_gap |
Numeric between |
group_annotation |
Optional named character vector or factor mapping every sample group to a coarser label. Factor levels set the legend order. Ignored if there is only one sample group. |
annotation_colours |
Optional named character vector of colours for
the |
palette |
String. Discrete palette for the group strips, see
|
.verbose |
Boolean. Controls verbosity of the extraction. |
A ggplot object.
Aibar, et al., Nat Methods, 2017
For each pathway of interest, draws the fitted null density at that pathway's size and drops the observed enrichment score on top, with the tail beyond it shaded. This is where the p-value comes from: blitzGSEA never permutes per pathway, it reads the score off the gamma tail interpolated to the set size.
The raw permutation scores never cross the Rust boundary, so this is the fitted density, not a histogram of null draws.
plot_blitzgsea_es_null( null_model, res, pathways_of_interest, n_points = 512L, text_size = 3 )plot_blitzgsea_es_null( null_model, res, pathways_of_interest, n_points = 512L, text_size = 3 )
null_model |
|
res |
data.table. Output of |
pathways_of_interest |
String vector. Names of the pathways to plot.
These need to be represented in |
n_points |
Integer. Resolution of the density curve. Defaults to |
text_size |
Numeric. Size of the annotation text. Defaults to |
A named list of ggplot objects, one per element of
pathways_of_interest.
Lachmann, et al., Bioinformatics, 2022
Diagnostic for a BlitzGseaNull. Shows the smoothed gamma parameters against
anchor set size for both tails, plus the fraction of positive null scores.
A fit that sags at one end of the size range is obvious here and invisible in
the results table.
The KS goodness-of-fit p-values are in the subtitle. Low values mean the gamma tails do not describe the permutation scores well and the p-values are optimistic. More permutations is the usual fix.
plot_blitzgsea_null(null_model, line_size = 0.8, point_size = 1.2)plot_blitzgsea_null(null_model, line_size = 0.8, point_size = 1.2)
null_model |
|
line_size |
Numeric. Line width. Defaults to |
point_size |
Numeric. Point size for the anchor knots. Defaults to
|
A ggplot object, facetted over the parameter type.
Lachmann, et al., Bioinformatics, 2022
Takes in the output from enrichment_map_oae() or
enrichment_map_gsea() and generates a ggraph object for
subsequent saving, etc.
plot_enrichment_map_ggraph( g, label_nodes = "adaptive", labels_to_include = NULL, adaptive_thresholds = c(`15` = 3, `5` = 2, `2` = 1, `1` = 0), font_size = 4, ... )plot_enrichment_map_ggraph( g, label_nodes = "adaptive", labels_to_include = NULL, adaptive_thresholds = c(`15` = 3, `5` = 2, `2` = 1, `1` = 0), font_size = 4, ... )
g |
igraph. Output from enrichment_map functions. |
label_nodes |
String. Controls which nodes to label. Options:
|
labels_to_include |
Optional string. These are labels you want to include no matter what. |
adaptive_thresholds |
Named numeric. The names indicate the community
size and the values how many pathways per community to show. An example would
be |
font_size |
Numeric. Font size of the labels on top of the enrichment map. |
... |
Other parameters you wish to forward to
|
A ggplot2 object with the enrichment map
Takes in the output from enrichment_map_oae() or
enrichment_map_gsea() and generates an interactive
VisNetwork widget.
plot_enrichment_map_visnetwork(g)plot_enrichment_map_visnetwork(g)
g |
igraph. Output from enrichment_map functions. |
The interactive visnetwork
This function can take in the output of bixverse::gse_hypergeometric() or
bixverse::gse_hypergeometric_list() and generates in the former case a
single plot and in the latter case a list of plots per target set.
plot_gse_dotplot( res, size_range = c(2, 5), viridis_option = "D", direction = -1, max_terms = NULL, .verbose = TRUE, ... )plot_gse_dotplot( res, size_range = c(2, 5), viridis_option = "D", direction = -1, max_terms = NULL, .verbose = TRUE, ... )
res |
data.table with the enrichment results. Needs to have the columns
|
size_range |
Numerical vector of size 2. Defines the size range for the dots in the plot. |
viridis_option |
String. The option to forward to
|
direction |
|
max_terms |
Optional integer. Show only the this many most significant
gene sets. Applied per target set when several were tested. Defaults to
|
.verbose |
Boolean. Controls verbosity of the function. |
... |
Further parameters to forward to
|
If the output of bixverse::gse_hypergeometric_list() was provided,
a list of dotplots per target gene set. Otherwise, a single GSE OAE dot plot.
Helper function to create the classical GSEA plots for a set of pathways of interest. You can also provide the underlying GSEA results to add the FDR and NES information to the plot.
plot_gsea_enrichment( stats, pathways, pathways_of_interest, gsea_results = NULL, gsea_param = 1, tick_size = 0.2, text_size = 5 )plot_gsea_enrichment( stats, pathways, pathways_of_interest, gsea_results = NULL, gsea_param = 1, tick_size = 0.2, text_size = 5 )
stats |
Named numeric vector. The gene level statistic. |
pathways |
List. A named list with each element containing the genes for this pathway. |
pathways_of_interest |
String vector. Names of the pathways to plot. These strings need to be represented in the names of pathways. |
gsea_results |
Optional data.table with the bixverse GSEA results. If provided, the FDR and NES for the given pathway of interest will be also added to the plot. |
gsea_param |
Numeric. Defaults to |
tick_size |
Numeric. The tick size. Defaults to |
text_size |
Numeric. The text size. Defaults to |
A named list of ggplot objects, one per element of
pathways_of_interest that survived the size filters.
Function that takes results from bixverse::calc_mitch(), extracts the
individual scores and p-values for each contrast, runs an FDR correction
on top of the p-values and sets scores above the provided FDR threshold to
0.
prepare_mitch_scores(res, fdr_threshold = 0.05)prepare_mitch_scores(res, fdr_threshold = 0.05)
res |
data.table. Output of |
fdr_threshold |
Numeric. The FDR threshold you want to apply. |
A list with the following two elements
fdr_corrections - FDR-corrected scores as a matrix of the individual contrast p-values.
adj_scores - The extract scores per contrast with scores above the individual FDR threshold set to 0.
General helper to save all types of plots to file
save_plot(plot, file_name = NULL, path, plot_params = params_plots())save_plot(plot, file_name = NULL, path, plot_params = params_plots())
plot |
The plot you want to save to disk. |
file_name |
Optional String. If not provided, the plot will be named after the R variable. |
path |
Directory. Where to save the plot to. |
plot_params |
List. Output of
|
Saves the plot to disk and returns invisible.
Save a list of plots
save_plot_ls(plot_ls, path, plot_params = params_plots())save_plot_ls(plot_ls, path, plot_params = params_plots())
plot_ls |
Named list of plots. The names will serve as file names (the extension will be added by the function) |
path |
Directory. Where to save the plot to. |
plot_params |
List. Output of
|
Saves the plots to disk and returns invisible.
Bixverse Color Scale (Discrete)
scale_color_bx(palette = "main", reverse = FALSE, ...)scale_color_bx(palette = "main", reverse = FALSE, ...)
palette |
Palette name (default: "main") |
reverse |
Reverse colors? (default: FALSE) |
... |
Additional arguments passed to scale_color_manual |
A ggplot2 scale object
Bixverse Color Scale (Continuous)
scale_color_bx_c(palette = "sequential", reverse = FALSE, n = 20, ...)scale_color_bx_c(palette = "sequential", reverse = FALSE, n = 20, ...)
palette |
Palette name (default: "sequential") |
reverse |
Reverse colors? (default: FALSE) |
n |
Integer. Number of colours to interpolate over (default: 20), see
|
... |
Additional arguments passed to scale_color_gradientn |
A ggplot2 scale object
Bixverse Fill Scale (Discrete)
scale_fill_bx(palette = "main", reverse = FALSE, ...)scale_fill_bx(palette = "main", reverse = FALSE, ...)
palette |
Palette name (default: "main") |
reverse |
Reverse colors? (default: FALSE) |
... |
Additional arguments passed to scale_fill_manual |
A ggplot2 scale object
Bixverse Fill Scale (Continuous)
scale_fill_bx_c(palette = "sequential", reverse = FALSE, n = 20, ...)scale_fill_bx_c(palette = "sequential", reverse = FALSE, n = 20, ...)
palette |
Palette name (default: "sequential") |
reverse |
Reverse colors? (default: FALSE) |
n |
Integer. Number of colours to interpolate over (default: 20), see
|
... |
Additional arguments passed to scale_fill_gradientn |
A ggplot2 scale object
Stacked violin plot of gene expression across groups
stacked_violin_plot_sc( object, features, grouping_variable, feature_labels = NULL, scale = FALSE, clip = NULL, modality = c("rna", "adt"), palette = BX_PALETTES )stacked_violin_plot_sc( object, features, grouping_variable, feature_labels = NULL, scale = FALSE, clip = NULL, modality = c("rna", "adt"), palette = BX_PALETTES )
object |
A single cell class. |
features |
Character vector. Gene IDs to plot, one row each. |
grouping_variable |
String. Obs column to group by. |
feature_labels |
Optional named character vector mapping gene ids to display labels (default: NULL). |
scale |
Boolean. Whether to z-score the expression values. |
clip |
Optional numeric. Clip z-scores if |
modality |
String. One of |
palette |
String. Discrete palette for the group fills. One of
|
A ggplot object.
A custom theme for the bixverse ecosystem based on the
ggplot2::theme_minimal()
theme_bx( base_size = 12, base_family = "Helvetica", base_line_size = 0.5, base_rect_size = 0.5 )theme_bx( base_size = 12, base_family = "Helvetica", base_line_size = 0.5, base_rect_size = 0.5 )
base_size |
Base font size (default: 12) |
base_family |
Base font family (default: "Helvetica") |
base_line_size |
Base line size (default: 0.5) |
base_rect_size |
Base rectangle size (default: 0.5) |
A ggplot2 theme object
## Not run: library(ggplot2) ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_bx() ## End(Not run)## Not run: library(ggplot2) ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + theme_bx() ## End(Not run)
Per-metric violin plots from a CellQc object
## S3 method for class 'CellQc' violin_plot_sc( x, log_scale = FALSE, show_outlier = TRUE, raster = NULL, palette = BX_PALETTES, ... )## S3 method for class 'CellQc' violin_plot_sc( x, log_scale = FALSE, show_outlier = TRUE, raster = NULL, palette = BX_PALETTES, ... )
x |
A |
log_scale |
Logical. Apply a log10 y-axis (default: FALSE). |
show_outlier |
Logical. Overlay outlier points (default: TRUE). |
raster |
Optional boolean. Shall the plot be rasterised. If |
palette |
String. Discrete palette for the group colours. One of
|
... |
Ignored. |
A named list of ggplot objects, one per metric.
Per-cell outliers are recomputed within each grouping_column group.
## S3 method for class 'data.table' violin_plot_sc( x, grouping_column, variable, direction = c("twosided", "below", "above"), threshold = 3, group_name = NULL, var_name = NULL, log_scale = TRUE, show_outlier = TRUE, raster = NULL, palette = BX_PALETTES, ... )## S3 method for class 'data.table' violin_plot_sc( x, grouping_column, variable, direction = c("twosided", "below", "above"), threshold = 3, group_name = NULL, var_name = NULL, log_scale = TRUE, show_outlier = TRUE, raster = NULL, palette = BX_PALETTES, ... )
x |
data.table. Input data containing the QC metric. |
grouping_column |
Character. Column used for the x-axis groups. |
variable |
Character. Numeric column to plot on the y-axis. |
direction |
Character. One of |
threshold |
Numeric. Number of MADs for outlier detection (default: 3). |
group_name |
Character. x-axis label (default: NULL). |
var_name |
Character. y-axis label (default: NULL). |
log_scale |
Logical. Apply a log10 y-axis (default: TRUE). |
show_outlier |
Logical. Overlay outlier points (default: TRUE). |
raster |
Optional boolean. Shall the plot be rasterised. If |
palette |
String. Discrete palette for the group colours. One of
|
... |
Ignored. |
A ggplot object.
Helper function to generate volcano plots for differental
gene/transcript/protein expression analysis. The function applies under the
hood a -log10(stat) transformation to the respective statistic you want
to display on the y axis. If you provide labels, the top features to label
will be chosen by ranking the -log10(stat).
volcano_plot( dt, volcano_plot_params = params_volcano(), x_lab = NULL, y_lab = NULL, plot_title = NULL, plot_sub_title = NULL )volcano_plot( dt, volcano_plot_params = params_volcano(), x_lab = NULL, y_lab = NULL, plot_title = NULL, plot_sub_title = NULL )
dt |
A data.table/data.frame holding the differential expression results. |
volcano_plot_params |
A list as returned by |
x_lab |
Optional string. Overwrite of the x label of the plot. If not
provided, will default to |
y_lab |
Optional string. Overwrite of the x label of the plot. If not
provided, will default to |
plot_title |
Optional string. If provided, the plot will get a title. |
plot_sub_title |
Optional string. If provided, adds this as a sub title to the plot. |
A ggplot object.
Helper function to wrap and truncate text
wrap_and_truncate(text, width = 40L, max_lines = 2L, whitespace_only = TRUE)wrap_and_truncate(text, width = 40L, max_lines = 2L, whitespace_only = TRUE)
text |
String. The string to truncate. |
width |
Integer. Maximum width of a given line. |
max_lines |
Integer. Maximum lines before truncating. |
whitespace_only |
Boolean. Shall the string wrapping happen only around whitespaces. |
The string wrapped and/or truncated.