Skip to contents

This function creates a scatter plot of spatial coordinates colored by labels. It is useful for visualizing spatial transcriptomics or spatial data with sample annotations.

Usage

STplot(coordinate, label, size = 1)

Arguments

coordinate

A data frame containing spatial coordinates. Must have columns named 'X' and 'Y'. Row names should correspond to spots or cells.

label

A named vector or factor of labels corresponding to the rows of `coordinate`. The function will reorder the labels to match the coordinate row order.

size

Numeric. The size of the points in the plot. Default is 1.

Value

A ggplot2 scatter plot object showing spatial distribution colored by label.

Author

Bin Duan

Examples

if (FALSE) { # \dontrun{
coord_df <- data.frame(X = runif(100), Y = runif(100))
rownames(coord_df) <- paste0("spot", 1:100)
labels <- sample(c("TypeA", "TypeB"), 100, replace = TRUE)
names(labels) <- rownames(coord_df)
STplot(coord_df, labels)
} # }