
Plot gene/feature expression trends across pseudotime
PlotFeatureTrend.RdSmoothed expression (or any numeric feature) vs. pseudotime, one facet
panel per feature, colored by group.by by default (or by
color.by, when that's set instead) to compare trends across
replicates or conditions. Equivalent to a geom_smooth() +
facet_wrap(~Gene) script run by hand, but feature extraction goes
through the same assay/version-safe path as the rest of scSidekick
(.nk_feature_matrix(), which is what every other feature-plotting
function in the package uses): genes are pulled via the
v5/BPCells/sketch-safe .get_layer_data(), and numeric
meta.data columns (module scores, cNMF usages, QC metrics, other
pseudotime columns, ...) are used directly - both are accepted
interchangeably in features.
Usage
PlotFeatureTrend(
seurat_object,
pseudotime.by,
features,
assay = NULL,
layer = "data",
min_expr = NULL,
donor.by = NULL,
color.by = NULL,
group.by = NULL,
groups = NULL,
split.by = NULL,
row.by = NULL,
method = "loess",
se = FALSE,
add_cor = FALSE,
cor_method = c("spearman", "pearson"),
show_points = FALSE,
point_size = 0.4,
point_alpha = 0.25,
scales = "free_y",
ncol = NULL,
colors = NULL,
output_dir = NULL,
object_name = "",
subset_name = "",
file_name = NULL,
width = NULL,
height = NULL,
timestamp = FALSE
)Arguments
- seurat_object
A Seurat object, typically after
RunSlingshot.- pseudotime.by
Character. Numeric
meta.datacolumn for the x-axis (e.g."Slingshot_Pseudotime_1").- features
Character vector. Gene names and/or numeric
meta.datacolumns. Each gets its own facet panel.- assay
Character or
NULL. Assay to pull gene expression from.NULL(default) usesDefaultAssay(seurat_object).- layer
Character. Assay layer/slot. Default
"data"(log-normalized counts).- min_expr
Numeric or
NULL. Expression floor applied before smoothing: observations with expression \(\le\)min_exprare dropped so the trend reflects the expressing population rather than being pulled toward zero by dropout.min_expr = 0removes exact zeros.NULL(default) keeps all cells.- donor.by
Character or
NULL. When a donor/patient column is given, cells are collapsed to one point per donor (mean x and mean y) before fitting, so both the trend and points reflect independent patients rather than cells. This is the honest way to relate a donor-level variable (e.g. age, a clinical score) to a per-cell value, and avoids drawing thousands of overlapping cell points.show_pointsdefaults toTRUEwhen this is set.NULL(default) keeps cell-level.- color.by
Character or
NULL. Metadata column to color the smoothed trend lines by (e.g."Sample", to see whether replicates agree).NULL(default) falls back togroup.byfor coloring, matching every other scSidekick plotting function's default; pass an explicitcolor.byto color by something other than the variable used to restrict cells.- group.by
Character or
NULL. Metadata column that (1) colors the trend lines whencolor.byisNULL, and (2), paired withgroups, restricts which cells are plotted (e.g. the trend within one cluster only) regardless of which variable ends up coloring the plot.- groups
Character vector or
NULL. Which level(s) ofgroup.byto keep.NULL(default, whengroup.byis set) keeps all levels.- split.by
Character or
NULL. Creates column facets - one figure panel per level, each drawn from an independent subset of cells (tiled with patchwork).NULL(default) = no column split.- row.by
Character or
NULL. Creates row facets, the same way assplit.by. Combined withsplit.byproduces a two-way grid.NULL(default) = no row split.- method
Character. Smoothing method passed to
ggplot2::geom_smooth()."loess"(default) fits a flexible, non-parametric curve - appropriate when the relationship's shape is unknown or non-monotonic. Use"lm"for a straight-line (linear) fit when the relationship looks linear/monotonic (e.g. after inspecting it withadd_cor = TRUE, or from prior knowledge of the variables);"glm"is also accepted for a generalized linear fit.- se
Logical. Show the smoother's standard-error ribbon. Default
FALSE.- add_cor
Logical. Annotate each facet with a correlation coefficient and p-value (via
ggpubr::stat_cor()), computed directly from the plotted x/y (donor-level whendonor.byis set) - this is the direct way to test the relationship shown by the trend line without routing throughCorrelateGene()/PlotCorrelation(), which are built around a gene-vs-many-genes screen keyed on a Seurat object rather than an arbitrary x/y pair. When a color variable is in effect (color.by, orgroup.byas its fallback), one annotation is shown per color group. DefaultFALSE.- cor_method
Character.
"spearman"(default; rank-based, appropriate for monotonic but not necessarily linear relationships) or"pearson"(linear correlation). Only used whenadd_cor = TRUE.- show_points
Logical. Overlay the raw observations under the trend. Besides showing individual points, this trains the y-axis on the full data range -
geom_smooth()alone auto-scales the axis to the fitted line, which can look "clipped" relative to the spread of the data. DefaultFALSE.- point_size, point_alpha
Size and transparency of the overlaid points when
show_points = TRUE. Defaults0.4and0.25.- scales
Character. Passed to
facet_wrap(). Default"free_y"(expression ranges differ across genes).- ncol
Integer or
NULL. Facet columns.NULLauto-picks.- colors
Named color vector for the coloring variable (
color.byor, when that'sNULL,group.by).NULLauto-resolves fromPrepObjectorNour_pal.- 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.- width, height
Numeric or
NULL. Saved PDF dimensions in inches.NULL(default) auto-sizes from the number of facets (or, withsplit.by/row.by, from the panel grid).- 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.