Skip to contents

This function creates a velocity plot for a given Seurat object. The plot shows the velocity vectors of the cells in a specified reduction space.

Usage

VelocityPlot(
  srt,
  reduction,
  dims = c(1, 2),
  cells = NULL,
  velocity = "stochastic",
  plot_type = c("raw", "grid", "stream"),
  group_by = NULL,
  group_palette = "Paired",
  group_palcolor = NULL,
  n_neighbors = ceiling(ncol(srt@assays[[1]])/50),
  density = 1,
  smooth = 0.5,
  scale = 1,
  min_mass = 1,
  cutoff_perc = 5,
  arrow_angle = 20,
  arrow_color = "black",
  streamline_L = 5,
  streamline_minL = 1,
  streamline_res = 1,
  streamline_n = 15,
  streamline_width = c(0, 0.8),
  streamline_alpha = 1,
  streamline_color = NULL,
  streamline_palette = "RdYlBu",
  streamline_palcolor = NULL,
  streamline_bg_color = "white",
  streamline_bg_stroke = 0.5,
  aspect.ratio = 1,
  title = "Cell velocity",
  subtitle = NULL,
  xlab = NULL,
  ylab = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  theme_use = "theme_scop",
  theme_args = list(),
  return_layer = FALSE,
  seed = 11
)

Arguments

srt

A Seurat object.

reduction

Name of the reduction in the Seurat object to use for plotting.

dims

Indices of the dimensions to use for plotting.

cells

Cells to include in the plot. If `NULL`, all cells will be included.

velocity

Name of the velocity to use for plotting. Default is `"stochastic"`.

plot_type

Type of plot to create. Can be `"raw"`, `"grid"`, or `"stream"`.

group_by

Name of the column in the Seurat object metadata to group the cells by. Defaults is `NULL`.

group_palette

Name of the palette to use for coloring the groups. Defaults is `"Paired"`.

group_palcolor

Colors to use for coloring the groups. Defaults is `NULL`.

n_neighbors

Number of neighbors to include for the density estimation. Defaults is `ceiling(ncol(srt@assays[[1]]) / 50)`.

density

Propotion of cells to plot. Defaults is `1` (plot all cells).

smooth

Smoothing parameter for density estimation. Defaults is `0.5`.

scale

Scaling factor for the velocity vectors. Defaults is `1`.

min_mass

Minimum mass value for the density-based cutoff. Defaults is `1`.

cutoff_perc

Percentile value for the density-based cutoff. Defaults is `5`.

arrow_angle

Angle of the arrowheads. Defaults is `20`.

arrow_color

Color of the arrowheads. Defaults is `"black"`.

streamline_L

Length of the streamlines. Defaults is `5`.

streamline_minL

Minimum length of the streamlines. Defaults is `1`.

streamline_res

Resolution of the streamlines. Defaults is `1`.

streamline_n

Number of streamlines to plot. Defaults is `15`.

streamline_width

Width of the streamlines. Defaults is `c(0, 0.8)`.

streamline_alpha

Alpha transparency of the streamlines. Defaults is `1`.

streamline_color

Color of the streamlines. Defaults is `NULL`.

streamline_palette

Name of the palette to use for coloring the streamlines. Defaults is `"RdYlBu"`.

streamline_palcolor

Colors to use for coloring the streamlines. Defaults is `NULL`.

streamline_bg_color

Background color of the streamlines. Defaults is `"white"`.

streamline_bg_stroke

Stroke width of the streamlines background. Defaults is `0.5`.

aspect.ratio

Aspect ratio of the plot. Defaults is 1.

title

Title of the plot. Defaults is `"Cell velocity"`.

subtitle

Subtitle of the plot. Defaults is NULL.

xlab

x-axis label. Defaults is NULL.

ylab

y-axis label. Defaults is NULL.

legend.position

Position of the legend. Defaults is `"right"`.

legend.direction

Direction of the legend. Defaults is `"vertical"`.

theme_use

Name of the theme to use for plotting. Defaults is `"theme_scop"`.

theme_args

List of theme arguments for customization. Defaults is `list()`.

return_layer

Whether to return the plot layers as a list. Defaults is `FALSE`.

seed

Random seed for reproducibility. Defaults is `11`.

See also

[RunSCVELO], [CellDimPlot]

Examples

PrepareEnv()
#>  [2025-09-20 14:00:06] Preparing scop Python Environment
#>  [2025-09-20 14:00:06] Environment name: scop_env
#>  [2025-09-20 14:00:06] Python version: 3.10-1
#>  [2025-09-20 14:00:06] Number of packages to install: 21
#>  [2025-09-20 14:00:07] Auto-detecting conda...
#>  [2025-09-20 14:00:07] Using existing environment: /usr/share/miniconda/envs/scop_env
#>  [2025-09-20 14:00:07] Checking and installing required packages...
#>  [2025-09-20 14:00:07] Installing conda packages
#>  [2025-09-20 14:00:09] Checking 3 packages in environment: scop_env
#>  [2025-09-20 14:00:09] Retrieving package list for environment: scop_env
#>  [2025-09-20 14:00:11] Found 197 packages installed
#>  [2025-09-20 14:00:11] leidenalg 0.10.2
#>  [2025-09-20 14:00:11] tbb 2022.2.0
#>  [2025-09-20 14:00:11] python-igraph 0.11.9
#>  [2025-09-20 14:00:11] Installing pip packages
#>  [2025-09-20 14:00:13] Checking 18 packages in environment: scop_env
#>  [2025-09-20 14:00:14] Retrieving package list for environment: scop_env
#>  [2025-09-20 14:00:16] Found 197 packages installed
#>  [2025-09-20 14:00:16] matplotlib 3.10.3
#>  [2025-09-20 14:00:16] numba 0.59.1
#>  [2025-09-20 14:00:16] llvmlite 0.42.0
#>  [2025-09-20 14:00:16] numpy 1.26.4
#>  [2025-09-20 14:00:16] palantir 1.4.1
#>  [2025-09-20 14:00:16] pandas 2.0.3
#>  [2025-09-20 14:00:16] scanpy 1.11.3
#>  [2025-09-20 14:00:16] scikit-learn 1.7.0
#>  [2025-09-20 14:00:16] scipy 1.15.3
#>  [2025-09-20 14:00:16] scvelo 0.3.3
#>  [2025-09-20 14:00:16] wot 1.0.8.post2
#>  [2025-09-20 14:00:16] trimap 1.1.4
#>  [2025-09-20 14:00:16] pacmap 0.8.0
#>  [2025-09-20 14:00:16] phate 1.0.11
#>  [2025-09-20 14:00:16] bbknn 1.6.0
#>  [2025-09-20 14:00:16] scanorama 1.7.4
#>  [2025-09-20 14:00:16] scvi-tools 1.2.1
#>  [2025-09-20 14:00:16] cellrank 2.0.7
#>  [2025-09-20 14:00:18] Python Environment Ready
#> conda environment: 
#>   conda:          /usr/share/miniconda/bin/conda
#>   environment:    /usr/share/miniconda/envs/scop_env
#> python config: 
#>   python:         /usr/share/miniconda/envs/scop_env/bin/python3.10
#>   libpython:      /usr/share/miniconda/envs/scop_env/lib/libpython3.10.so
#>   pythonhome:     /usr/share/miniconda/envs/scop_env:/usr/share/miniconda/envs/scop_env
#>   version:        3.10.1 | packaged by conda-forge | (main, Dec 22 2021, 01:39:36) [GCC 9.4.0]
#>   numpy:          /usr/share/miniconda/envs/scop_env/lib/python3.10/site-packages/numpy
#>   numpy_version:  1.26.4
#>   
#>   NOTE: Python version was forced by use_python() function
data(pancreas_sub)
pancreas_sub <- standard_scop(pancreas_sub)
#>  [2025-09-20 14:00:19] Start standard scop workflow...
#>  [2025-09-20 14:00:20] Checking a list of <Seurat> object...
#> ! [2025-09-20 14:00:20] Data 1/1 of the `srt_list` is "unknown"
#>  [2025-09-20 14:00:20] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 1/1 of the `srt_list`...
#>  [2025-09-20 14:00:22] Perform `Seurat::FindVariableFeatures()` on the data 1/1 of the `srt_list`...
#>  [2025-09-20 14:00:22] Use the separate HVF from srt_list
#>  [2025-09-20 14:00:22] Number of available HVF: 2000
#>  [2025-09-20 14:00:23] Finished check
#>  [2025-09-20 14:00:23] Perform `Seurat::ScaleData()`
#> Warning: Different features in new layer data than already exists for scale.data
#>  [2025-09-20 14:00:23] Perform pca linear dimension reduction
#> StandardPC_ 1 
#> Positive:  Aplp1, Cpe, Gnas, Fam183b, Map1b, Hmgn3, Pcsk1n, Chga, Tuba1a, Bex2 
#> 	   Syt13, Isl1, 1700086L19Rik, Pax6, Chgb, Scgn, Rbp4, Scg3, Gch1, Camk2n1 
#> 	   Cryba2, Pcsk2, Pyy, Tspan7, Mafb, Hist3h2ba, Dbpht2, Abcc8, Rap1b, Slc38a5 
#> Negative:  Spp1, Anxa2, Sparc, Dbi, 1700011H14Rik, Wfdc2, Gsta3, Adamts1, Clu, Mgst1 
#> 	   Bicc1, Ldha, Vim, Cldn3, Cyr61, Rps2, Mt1, Ptn, Phgdh, Nudt19 
#> 	   Smtnl2, Smco4, Habp2, Mt2, Col18a1, Rpl12, Galk1, Cldn10, Acot1, Ccnd1 
#> StandardPC_ 2 
#> Positive:  Rbp4, Tagln2, Tuba1b, Fkbp2, Pyy, Pcsk2, Iapp, Tmem27, Meis2, Tubb4b 
#> 	   Pcsk1n, Dbpht2, Rap1b, Dynll1, Tubb2a, Sdf2l1, Scgn, 1700086L19Rik, Scg2, Abcc8 
#> 	   Atp1b1, Hspa5, Fam183b, Papss2, Slc38a5, Scg3, Mageh1, Tspan7, Ppp1r1a, Ociad2 
#> Negative:  Neurog3, Btbd17, Gadd45a, Ppp1r14a, Neurod2, Sox4, Smarcd2, Mdk, Pax4, Btg2 
#> 	   Sult2b1, Hes6, Grasp, Igfbpl1, Gpx2, Cbfa2t3, Foxa3, Shf, Mfng, Tmsb4x 
#> 	   Amotl2, Gdpd1, Cdc14b, Epb42, Rcor2, Cotl1, Upk3bl, Rbfox3, Cldn6, Cer1 
#> StandardPC_ 3 
#> Positive:  Nusap1, Top2a, Birc5, Aurkb, Cdca8, Pbk, Mki67, Tpx2, Plk1, Ccnb1 
#> 	   2810417H13Rik, Incenp, Cenpf, Ccna2, Prc1, Racgap1, Cdk1, Aurka, Cdca3, Hmmr 
#> 	   Spc24, Kif23, Sgol1, Cenpe, Cdc20, Hist1h1b, Cdca2, Mxd3, Kif22, Ska1 
#> Negative:  Anxa5, Pdzk1ip1, Acot1, Tpm1, Anxa2, Dcdc2a, Capg, Sparc, Ttr, Pamr1 
#> 	   Clu, Cxcl12, Ndrg2, Hnf1aos1, Gas6, Gsta3, Krt18, Ces1d, Atp1b1, Muc1 
#> 	   Hhex, Acadm, Spp1, Enpp2, Bcl2l14, Sat1, Smtnl2, 1700011H14Rik, Tgm2, Fam159a 
#> StandardPC_ 4 
#> Positive:  Glud1, Tm4sf4, Akr1c19, Cldn4, Runx1t1, Fev, Pou3f4, Gm43861, Pgrmc1, Arx 
#> 	   Cd200, Lrpprc, Hmgn3, Ppp1r14c, Pam, Etv1, Tsc22d1, Slc25a5, Akap17b, Pgf 
#> 	   Fam43a, Emb, Jun, Krt8, Dnajc12, Mid1ip1, Ids, Rgs17, Uchl1, Alcam 
#> Negative:  Ins2, Ins1, Ppp1r1a, Nnat, Calr, Sytl4, Sdf2l1, Iapp, Pdia6, Mapt 
#> 	   G6pc2, C2cd4b, Npy, Gng12, P2ry1, Ero1lb, Adra2a, Papss2, Arhgap36, Fam151a 
#> 	   Dlk1, Creld2, Gip, Tmem215, Gm27033, Cntfr, Prss53, C2cd4a, Lyve1, Ociad2 
#> StandardPC_ 5 
#> Positive:  Pdx1, Nkx6-1, Npepl1, Cldn4, Cryba2, Fev, Jun, Chgb, Gng12, Adra2a 
#> 	   Mnx1, Sytl4, Pdk3, Gm27033, Nnat, Chga, Ins2, 1110012L19Rik, Enho, Krt7 
#> 	   Mlxipl, Tmsb10, Flrt1, Pax4, Tubb3, Prrg2, Gars, Frzb, BC023829, Gm2694 
#> Negative:  Irx2, Irx1, Gcg, Ctxn2, Tmem27, Ctsz, Tmsb15l, Nap1l5, Pou6f2, Gria2 
#> 	   Ghrl, Peg10, Smarca1, Arx, Lrpap1, Rgs4, Ttr, Gast, Tmsb15b2, Serpina1b 
#> 	   Slc16a10, Wnk3, Ly6e, Auts2, Sct, Arg1, Dusp10, Sphkap, Dock11, Edn3 
#>  [2025-09-20 14:00:24] Perform `Seurat::FindClusters()` with louvain and `cluster_resolution` = 0.6
#>  [2025-09-20 14:00:24] Reorder clusters...
#> ! [2025-09-20 14:00:24] Using `Seurat::AggregateExpression()` to calculate pseudo-bulk data for <Assay5>
#>  [2025-09-20 14:00:24] Perform umap nonlinear dimension reduction
#>  [2025-09-20 14:00:24] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2025-09-20 14:00:24] UMAP will return its model
#>  [2025-09-20 14:00:29] Non-linear dimensionality reduction (umap) using (Standardpca) dims (1-50) as input
#>  [2025-09-20 14:00:29] UMAP will return its model
#>  [2025-09-20 14:00:33] Run scop standard workflow done
pancreas_sub <- RunSCVELO(
  pancreas_sub,
  group_by = "SubCellType",
  linear_reduction = "pca",
  nonlinear_reduction = "umap",
  return_seurat = TRUE
)
#>  [2025-09-20 14:00:35] Checking 1 packages in environment: scop_env
#>  [2025-09-20 14:00:35] Retrieving package list for environment: scop_env
#>  [2025-09-20 14:00:37] Found 197 packages installed
#>  [2025-09-20 14:00:37] scvelo version: 0.3.3
#>  [2025-09-20 14:00:39] Checking 2 packages in environment: scop_env
#>  [2025-09-20 14:00:40] Retrieving package list for environment: scop_env
#>  [2025-09-20 14:00:42] Found 197 packages installed
#>  [2025-09-20 14:00:42] scanpy version: 1.11.3
#>  [2025-09-20 14:00:42] numpy version: 1.26.4
#>  [2025-09-20 14:00:42] Converting <Seurat> to <AnnData> ...
#> ! [2025-09-20 14:00:42] "misc" slot is not converted
#> ! [2025-09-20 14:00:42] "tools" slot is not converted
#>  [2025-09-20 14:00:42] Convert <Seurat> object to <AnnData> object completed
#>  [2025-09-20 14:00:42] Running scVelo analysis...
#>  [2025-09-20 14:00:47] scVelo analysis completed
#>  [2025-09-20 14:00:47] Converting <AnnData> object to <Seurat> object...
#>  [2025-09-20 14:00:51] Convert <AnnData> object to <Seurat> object completed
#> Warning: Different features in new layer data than already exists for counts
#> Warning: Different features in new layer data than already exists for data
VelocityPlot(
  pancreas_sub,
  reduction = "UMAP"
)
#>  [2025-09-20 14:00:55] metR installed successfully


VelocityPlot(
  pancreas_sub,
  reduction = "UMAP",
  group_by = "SubCellType"
)
#>  [2025-09-20 14:00:55] metR installed successfully
#> Error in vapply(glyph, get_attr, which = "width", default = 0, numeric(1)): values must be length 1,
#>  but FUN(X[[1]]) result is length 1000

VelocityPlot(
  pancreas_sub,
  reduction = "UMAP",
  plot_type = "grid"
)
#>  [2025-09-20 14:00:55] metR installed successfully


VelocityPlot(
  pancreas_sub,
  reduction = "UMAP",
  plot_type = "stream"
)
#>  [2025-09-20 14:00:56] metR installed successfully
#>  [2025-09-20 14:00:56] metR installed successfully


VelocityPlot(
  pancreas_sub,
  reduction = "UMAP",
  plot_type = "stream",
  streamline_color = "black"
)
#>  [2025-09-20 14:00:56] metR installed successfully
#>  [2025-09-20 14:00:57] metR installed successfully


VelocityPlot(
  pancreas_sub,
  reduction = "UMAP",
  plot_type = "stream",
  streamline_color = "black",
  arrow_color = "red"
)
#>  [2025-09-20 14:00:57] metR installed successfully
#>  [2025-09-20 14:00:57] metR installed successfully