| plotDimRed {ggspavis} | R Documentation |
Plotting functions for spatially resolved transcriptomics data.
plotDimRed(
spe,
type = c("UMAP", "PCA"),
x_axis = NULL,
y_axis = NULL,
annotate = NULL,
palette = "libd_layer_colors",
size = 0.3
)
spe |
(SpatialExperiment) Input data, assumed to be a
|
type |
(character) Type of reduced dimension plot. Options are "UMAP" or "PCA". Default = "UMAP". |
x_axis |
(character) Name of column in |
y_axis |
(character) Name of column in |
annotate |
(character) Name of column in |
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. |
size |
(numeric) Point size for |
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.
Returns a ggplot object. Additional plot elements can be added as ggplot elements (e.g. title, labels, formatting, etc).
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")