plotDimRed {ggspavis}R Documentation

plotDimRed

Description

Plotting functions for spatially resolved transcriptomics data.

Usage

plotDimRed(
  spe,
  type = c("UMAP", "PCA"),
  x_axis = NULL,
  y_axis = NULL,
  annotate = NULL,
  palette = "libd_layer_colors",
  size = 0.3
)

Arguments

spe

(SpatialExperiment) Input data, assumed to be a SpatialExperiment object.

type

(character) Type of reduced dimension plot. Options are "UMAP" or "PCA". Default = "UMAP".

x_axis

(character) Name of column in reducedDim containing x-coordinates. Default = "UMAP1" or "PC1", depending on plot type.

y_axis

(character) Name of column in reducedDim containing y-coordinates. Default = "UMAP2" or "PC2", depending on plot type.

annotate

(character) Name of column in colData containing values to annotate spots with colors, e.g. cluster labels (discrete values) or total UMI counts (continuous values). For discrete values such as cluster labels, the column in colData should be formatted as a factor.

palette

(character) Color palette for annotation. Options for discrete labels are "libd_layer_colors", "Okabe-Ito", or a vector of color names or hex values. For continuous values, provide a vector of length 2 for the low and high range, e.g. c("gray90", "navy"). Default = "libd_layer_colors".

size

(numeric) Point size for geom_point(). Default = 0.3.

Details

Function to plot spot-based spatially resolved transcriptomics data stored in a SpatialExperiment object.

This function generates a plot in reduced dimension coordinates (PCA or UMAP), along with annotation such as cluster labels or total UMI counts.

Value

Returns a ggplot object. Additional plot elements can be added as ggplot elements (e.g. title, labels, formatting, etc).

Examples

library(STexampleData)
spe <- Visium_humanDLPFC()

# use small subset of data for this example
# for longer examples see our online book OSTA
spe <- spe[, spatialData(spe)$in_tissue == 1]
set.seed(100)
n <- 200
spe <- spe[, sample(seq_len(ncol(spe)), n)]

# calculate log-transformed normalized counts
library(scran)
set.seed(100)
qclus <- quickCluster(spe)
spe <- computeSumFactors(spe, cluster = qclus)
spe <- logNormCounts(spe)

# identify top highly variable genes (HVGs)
is_mito <- grepl("(^MT-)|(^mt-)", rowData(spe)$gene_name)
spe <- spe[!is_mito, ]
dec <- modelGeneVar(spe)
top_hvgs <- getTopHVGs(dec, prop = 0.1)

# run dimensionality reduction
library(scater)
set.seed(100)
spe <- runPCA(spe, subset_row = top_hvgs)
set.seed(100)
spe <- runUMAP(spe, dimred = "PCA")
colnames(reducedDim(spe, "UMAP")) <- paste0("UMAP", 1:2)

# generate plot
plotDimRed(spe, type = "UMAP", annotate = "ground_truth")


[Package ggspavis version 1.0.0 Index]