
Density or ridge plot for any gene or numeric metadata feature
PlotFeatureDistribution.RdA more general version of Seurat's RidgePlot() - one density
(or ridge) per group.by level, for any single feature - but with
the two things RidgePlot() does not support: a split.by fill
within each ridge, and a facet.by panel split. That combination
answers questions like "one ridge per Sample, one panel per Response" to
check whether replicate samples show the same distribution shape within
each condition.
feature is resolved the same assay/version-safe way as every other
feature-plotting function in the package (.nk_feature_matrix()):
gene names go through .get_layer_data() (v5/BPCells/sketch-safe),
numeric meta.data columns (a pseudotime, a module score, a QC
metric, ...) are used directly.
Usage
PlotFeatureDistribution(
seurat_object,
feature,
group.by,
split.by = NULL,
facet.by = NULL,
style = c("ridge", "density"),
assay = NULL,
layer = "data",
min_expr = NULL,
colors = NULL,
scales = "fixed",
ncol = NULL,
output_dir = NULL,
object_name = "",
subset_name = "",
file_name = NULL,
width = NULL,
height = NULL
)Arguments
- seurat_object
A Seurat object.
- feature
Character vector. One or more gene names and/or numeric
meta.datacolumns. When several are supplied, one PDF is written per feature (the file name always includes the feature).- group.by
Character. Categorical
meta.datacolumn - one density/ridge per level.- split.by
Character or
NULL. Categoricalmeta.datacolumn used as a secondary fill within eachgroup.byridge. Only used whenstyle = "ridge".- facet.by
Character or
NULL. Categoricalmeta.datacolumn to split the whole plot into panels viafacet_wrap()(e.g.group.by = "Sample",facet.by = "Response"to check whether replicates overlap within each response group).- style
"ridge"(default, viaggridges) or"density"(overlaidgeom_density()curves, fill =group.by;split.byis ignored for this style).- assay
Character or
NULL. Assay to pull gene expression from.NULL(default) usesDefaultAssay(seurat_object).- layer
Character. Assay layer/slot. Default
"data".- min_expr
Numeric or
NULL. Expression floor: cells with expression \(\le\)min_exprare excluded so the distribution reflects the expressing population rather than a spike at zero from dropout.min_expr = 0removes exact zeros.NULL(default) keeps all cells.- colors
Named color vector for the fill variable (
split.byif set, elsegroup.by).NULLauto-resolves fromPrepObjectorNour_pal.- scales
Character. Passed to
facet_wrap()whenfacet.byis set. Default"fixed"(keeps axes directly comparable across panels - usually what you want when checking whether distributions overlap).- ncol
Integer or
NULL. Facet columns.NULLauto-picks.- output_dir
Character or
NULL. Directory to save a PDF.NULL(default) walks up to theoutput_dirstored byPrepObject(respectingAutoSavePlots); passNAto suppress entirely.- object_name, subset_name
Character. Output file-name prefixes.
- file_name
Character or
NULL. Base name (no extension) for the saved PDF.NULLauto-deduces a name that includes the feature,group.byandsplit.by. Whenfile_nameis given and several features are requested, the feature is appended so each still gets its own file.- width, height
Numeric or
NULL. Saved PDF dimensions in inches.NULL(default) auto-sizes.