Skip to contents

Plots any two metadata columns as a scatter plot, colored by an optional grouping variable. Designed for visualizing relationships between Markov analysis scores (e.g., attractor score vs. hitting time, commitment probability vs. module eigengene) but works with any numeric metadata pair.

Usage

PlotMarkovScatter(
  seurat_obj,
  x_feature,
  y_feature,
  color.by = NULL,
  color_palette = NULL,
  pt_size = 0.8,
  alpha = 0.6,
  add_smooth = FALSE,
  smooth_method = "loess",
  smooth_se = TRUE,
  hline = NULL,
  hline_color = "grey40",
  hline_linetype = "dashed",
  vline = NULL,
  vline_color = "grey40",
  vline_linetype = "dashed",
  x_label = NULL,
  y_label = NULL,
  title = NULL,
  legend_title = NULL
)

Arguments

seurat_obj

A Seurat object with all requested features in @meta.data.

x_feature

Character. Metadata column for the x-axis.

y_feature

Character. Metadata column for the y-axis.

color.by

Character or NULL. Metadata column for point color. If NULL, all points are drawn in a single color ("#2166AC").

color_palette

Named character vector or NULL. Named color vector for categorical color.by groups passed to scale_color_manual. If NULL, ggplot2 default colors are used. Ignored when color.by is numeric.

pt_size

Numeric. Point size. Default: 0.8.

alpha

Numeric. Point transparency. Default: 0.6.

add_smooth

Logical. Add a smoothing line via geom_smooth. Default: FALSE.

smooth_method

Character. Smoothing method passed to geom_smooth (e.g., "loess", "lm"). Default: "loess".

smooth_se

Logical. Show confidence interval band around the smooth line. Default: TRUE.

hline

Numeric or NULL. Y-value for a horizontal reference line. NULL = no line. Drawn under the point layer. Default: NULL.

hline_color

Character. Color for the horizontal reference line. Default: "grey40".

hline_linetype

Character. Linetype for the horizontal reference line. Default: "dashed".

vline

Numeric or NULL. X-value for a vertical reference line. NULL = no line. Drawn under the point layer. Default: NULL.

vline_color

Character. Color for the vertical reference line. Default: "grey40".

vline_linetype

Character. Linetype for the vertical reference line. Default: "dashed".

x_label

Character or NULL. X-axis label. If NULL, defaults to x_feature.

y_label

Character or NULL. Y-axis label. If NULL, defaults to y_feature.

title

Character or NULL. Plot title.

legend_title

Character or NULL. Legend title. If NULL, defaults to color.by.

Value

A ggplot2 object.

Details

Color handling adapts to the type of color.by:

  • NULL: fixed single color.

  • Numeric column: sequential gradient via scale_color_gradientn.

  • Factor/character column: discrete colors via scale_color_manual (if color_palette provided) or scale_color_discrete.

Reference lines (hline, vline) are drawn before the point layer so they sit under the points.