R/spot_plot.R
spot_plot.Rd
This function is essentially a wrapper around spatialLIBD::vis_clus
and
spatialLIBD::vis_gene
, suitable for merged samples (each sample in the
SpatialExperiment 'spe' is a donor consisting of multiple capture areas, with
colData column 'exclude_overlapping' indicating overlapping spots to drop (to
prevent overplotting).
A SpatialExperiment
with colData column exclude_overlapping
,
passed to spatialLIBD::vis_gene
or spatialLIBD::vis_clus
character(1) passed to sampleid
in
spatialLIBD::vis_gene
or spatialLIBD::vis_clus
. Assumed to be a
donor, possibly consisting of several capture areas to plot at once
character(1) giving the name of the image (e.g. "lowres") to
plot, used both to determine an appropriate spot size and passed to
spatialLIBD::vis_gene
or spatialLIBD::vis_clus
character(1) giving the title of the plot
character() passed to geneid
for spatialLIBD::vis_gene
or character(1) passed to clustervar
for spatialLIBD::vis_clus
A character(1)
: either "pca", "sparsity", or
"z_score". This parameter controls how multiple continuous variables are
combined for visualization, and only applies when var_name
has length > 1
and is_discrete
is FALSE
logical(1): if FALSE, remove the plot legend
logical(1): if TRUE, use spatialLIBD::vis_clus
;
otherwise, use spatialLIBD::vis_gene
character() of colors passed to colors
for spatialLIBD::vis_clus
if is_discrete
or otherwise to cont_colors
for spatialLIBD::vis_gene
character(1) passed to spatialLIBD::vis_gene
if
not is_discrete
numeric(1) passed to passed to spatialLIBD::vis_gene
if
not is_discrete
logical(1) passed to sampleid
in
spatialLIBD::vis_gene
or spatialLIBD::vis_clus
A ggplot
object containing a "spot plot" of the specified sample
Spot sizes are almost consistent among donors, regardless of full- resolution image dimensions, when title is NULL, include_legend is FALSE, and the plot is saved to a square output (e.g. PDF with 7in width and height). However, ggplot does not seem to scale plots of different aspect ratios exactly consistently when writing to PDF (untested for other formats)
# Grab an example SpatialExperiment and suppose all of its spots should be
# plotted (for spatialNAc, 'exclude_overlapping' will only have genuinely
# overlapping spots be TRUE)
spe <- if (!exists("spe")) {
spatialLIBD::fetch_data(type = "spatialDLPFC_Visium_example_subset")
}
#> 2024-06-06 17:41:16.613515 loading file /github/home/.cache/R/BiocFileCache/6fb23c6a6be_spatialDLPFC_spe_subset_example.rds%3Fdl%3D1
spe$exclude_overlapping <- FALSE
# Plot age spatially for the first sample
sample_id <- unique(spe$sample_id)[1]
p <- spot_plot(
spe,
sample_id = sample_id,
title = sample_id, var_name = "age",
include_legend = TRUE, is_discrete = FALSE, minCount = 0,
assayname = "logcounts"
)
print(p)
# Define several markers for white matter
white_matter_genes <- c(
"ENSG00000197971", "ENSG00000131095", "ENSG00000123560",
"ENSG00000171885"
)
# Plot multiple white matter genes simultaneously for the first sample.
# Use the "pca" method for combining them
p <- spot_plot(
spe,
sample_id = sample_id,
title = sample_id, var_name = white_matter_genes,
multi_gene_method = "pca", include_legend = TRUE, is_discrete = FALSE,
minCount = 0, assayname = "logcounts"
)
print(p)