Skip to contents

Spatial spot plot

Usage

SpatialSpotPlot(
  object = NULL,
  group.by = NULL,
  features = NULL,
  assay = NULL,
  layer = "data",
  values = NULL,
  plot_type = c("point", "pie"),
  plot.data = NULL,
  spot.by = NULL,
  color.by = NULL,
  geom = c("point", "jitter"),
  image = NULL,
  overlay_image = TRUE,
  image.alpha = 1,
  crop = TRUE,
  coord.cols = c("col", "row"),
  flip.y = NULL,
  show_axes = FALSE,
  split.by = NULL,
  cells = NULL,
  show_na = FALSE,
  pt.size = NULL,
  pie.radius = NULL,
  pie.radius.scale = 0.45,
  pt.alpha = 0.9,
  stroke = 0.1,
  jitter_width = 0.25,
  jitter_height = 0.25,
  palette = "Spectral",
  palcolor = NULL,
  bg_color = "grey20",
  lower_quantile = 0,
  upper_quantile = 0.99,
  lower_cutoff = NULL,
  upper_cutoff = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  legend.title = NULL,
  theme_use = "theme_spatial",
  theme_args = list(),
  combine = TRUE,
  nrow = NULL,
  ncol = NULL,
  byrow = TRUE,
  verbose = TRUE,
  srt = NULL,
  image.scale = c("lowres", "hires"),
  xlim = NULL,
  ylim = NULL,
  molecules = NULL,
  mols.size = 0.1,
  mols.alpha = 1,
  mols.colors = NULL
)

Arguments

object

A Seurat object.

group.by

Metadata columns to color spots by.

features

Features to color spots by (from assay/layer).

assay

Assay to use. NULL uses the default assay.

layer

Assay layer to use.

values

Spot-level values (named vector, matrix, or data.frame).

plot_type

"point" or "pie". Pie uses numeric group.by columns, values, or "<prefix>_prop_*"/"<prefix>_frac_*" when group.by is "<prefix>_dominant_type".

plot.data, spot.by, color.by

Long-format data for repeated spatial points (e.g. cell-to-spot assignments).

geom

"point" or "jitter" for plot.data.

image

Spatial image name. Required when multiple images are present; a single image is selected automatically when NULL.

overlay_image, image.alpha

Draw the spatial image beneath spots.

crop

Crop the panel to plotted spots.

coord.cols

Metadata coordinate columns used when no image is available.

flip.y

Reverse the y axis for coordinates without a Visium raster. NULL follows official FOV display orientation (y increasing downward), while metadata coordinates retain their orientation. Use FALSE for the historical FOV layout. Visium display coordinates already include a flip.

show_axes

Keep axis text, ticks, and grid when theme_use is "theme_spatial".

split.by

Metadata column to facet by.

cells

Cell names to include.

show_na

If TRUE, color NA groups with bg_color; if FALSE, drop them.

pt.size, pt.alpha

Point size and transparency. pt.size = NULL scales with sqrt(n) (minimum 0.3). Rasterized points keep at least a two-pixel radius at raster.dpi = c(512, 512) and scale with raster.dpi.

pie.radius, pie.radius.scale

Pie radius. NULL estimates from spot spacing, then multiplies by pie.radius.scale.

stroke

Point border width.

jitter_width, jitter_height

Jitter when geom = "jitter".

palette, palcolor

Palette name (thisplot::show_palettes) or custom colors.

bg_color

Point border color.

lower_quantile, upper_quantile, lower_cutoff, upper_cutoff

Limits for continuous feature scales. Non-NULL cutoffs take precedence over the quantiles.

legend.position, legend.direction, legend.title

Legend placement ("none", "left", "right", "bottom", "top"), direction, and title. legend.title = NULL uses the group name.

theme_use

Theme name or function.

theme_args

Theme name or function, plus extra theme arguments.

combine, nrow, ncol, byrow

Combine plots with patchwork::patchwork. combine = FALSE returns a list of ggplots.

verbose

Whether to print messages.

srt

Deprecated alias for object; supply exactly one of the two. It will be removed in scop 1.0.0.

image.scale

Image scale factor matching the raster stored in the selected image. For Visium overlays, a hires request fails if no spot centers fit the raster at hires but all fit at lowres.

xlim, ylim

Optional increasing ROI limits in raw coordinates. Cells are selected by centroid; limits clip the display without modifying object.

molecules

Optional names of already loaded molecules to overlay. No files are read. Molecules are filtered by ROI, not assigned to cells.

mols.size, mols.alpha, mols.colors

Molecule size, opacity, and optional named colors matched to molecule names.

Value

A ggplot, patchwork, or list of ggplot objects.

Details

Factor levels retain their order, including after selecting cells. Named palcolor vectors map category names to colors; unnamed colors follow factor order. Missing values remain distinct from a category named "NA". Long-format point/jitter plots honor cutoff and quantile controls and return a named one-element list when combine = FALSE. Their default continuous range remains the full data range; an explicitly supplied upper_quantile overrides that default.

Examples

data(visium_human_pancreas_sub)
SpatialSpotPlot(
  object = visium_human_pancreas_sub,
  group.by = "coda_label"
)


SpatialSpotPlot(
  object = visium_human_pancreas_sub,
  features = rownames(visium_human_pancreas_sub)[1:2],
  layer = "counts"
)