
Overlay a Slingshot trajectory on a DimPlot
PlotTrajectory.RdDraws a standard cluster DimPlot with the Slingshot trajectory overlaid, in one of two styles:
style = "straight"(default) - straight segments between cluster centroids, following the cluster-level minimum spanning tree Slingshot fit (slingshot::slingMST()). This is the clean, DDRTree-like look that stays legible with many clusters, and works on any plot reduction since only the MST's cluster connectivity is reused - the node positions come from this plot's own reduction.style = "curves"- Slingshot's smoothed per-lineage principal curves (slingshot::slingCurves()). These live in whatever reduction Slingshot was fit on, so this style requiresreductionto matchseurat_object@misc$slingshot$reduction(e.g. fit and plot both on"umap"); otherwise the curve coordinates would not correspond to the plotted axes, and this function stops rather than draw a misleading overlay.
Usage
PlotTrajectory(
seurat_object,
reduction = "umap",
group.by = NULL,
split.by = NULL,
row.by = NULL,
lineages = NULL,
style = c("straight", "curves"),
colors = NULL,
pt.size = 0.4,
line.color = "black",
line.width = 0.8,
label_lineages = TRUE,
arrow = TRUE,
label = TRUE,
number_labels = FALSE,
legend.side = "bottom",
legend_nrow = 2,
output_dir = NULL,
object_name = "",
subset_name = "",
file_name = NULL,
width = NULL,
height = NULL,
timestamp = FALSE
)Arguments
- seurat_object
A Seurat object previously processed by
RunSlingshot.- reduction
Character. Reduction to plot on. Default
"umap".- group.by
Character or
NULL. Metadata column for point color.NULL(default) uses thecluster.bystored byRunSlingshot.- split.by
Character or
NULL. Metadata column for columns in a multi-panel grid (e.g. one panel per sample/condition).NULL(default) walks up to thesplit.bystored byPrepObject; a single panel is drawn when neither this norrow.byis set. Each panel reuses the same fitted Slingshot model - only which cells are drawn differs - and the whole grid shares one legend, matchingPlotDimPlots.- row.by
Character or
NULL. Metadata column for rows in the grid, combined withsplit.byfor a two-way facet.NULL(default; no row faceting).- lineages
Integer/character vector or
NULL. Which lineages to draw (e.g.c(1, 2)orc("Lineage1", "Lineage2")).NULL(default) draws all.- style
"straight"or"curves". See Description.- colors
Named color vector.
NULLauto-resolves fromPrepObjectorNour_pal.- pt.size
Numeric. Point size. Default
0.4.- line.color
Character. Trajectory line color. Default
"black".- line.width
Numeric. Trajectory line width. Default
0.8.- label_lineages
Logical. When more than one lineage is drawn, map line type (solid/dashed/dotted/...) to lineage and add a "Lineage" legend, so overlapping trajectory lines can be told apart. Color is left alone (still
line.color) so this doesn't collide with the cluster color legend. DefaultTRUE; has no visible effect (and no legend) when only one lineage is drawn.- arrow
Logical. Draw arrowheads on straight segments (ignored for
style = "curves", which is unordered per point). DefaultTRUE.- label
Logical. Label cluster centroids. Default
TRUE.- number_labels
Logical. When
TRUE, both the legend and (iflabel = TRUE) the centroid labels use a zero-padded index (e.g., legend "01. CellType", centroid "01") instead of the actual cluster name, matchingPlotDimPlots's convention. Useful when there are many clusters or the names are too long to label directly on the plot. DefaultFALSE(legend and centroid labels show the real cluster name, unnumbered).- legend.side
Character. Legend position, matching
PlotDimPlots:"bottom"(default),"top","left", or"right".- legend_nrow
Integer. Rows for the cluster legend when
legend.sideis"bottom"/"top". Default2, matchingPlotDimPlots's default - keeping this the same makes the two functions' output comparable side by side.- 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) uses a fixed 6 x 5.5 in panel (scaled up per grid panel whensplit.by/row.byis set).- 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.