Plot the simulations as a density plot or histogram compared to the observed
Moran's I or Geary's C, with ggplot2 so it looks nicer. Unlike the plotting
function in spdep
, this function can also plot the same feature in
different samples as facets or plot different features or samples together
for comparison.
Arguments
- sfe
A
SpatialFeatureExperiment
object.- features
Features to plot, must be in rownames of the gene count matrix, colnames of colData or a colGeometry, colnames of cell embeddings in
reducedDim
, or numeric indices of dimension reduction components.- sample_id
Sample(s) in the SFE object whose cells/spots to use. Can be "all" to compute metric for all samples; the metric is computed separately for each sample.
- facet_by
Whether to facet by sample_id (default) or features. If facetting by sample_id, then different features will be plotted in the same facet for comparison. If facetting by features, then different samples will be compared for each feature. Ignored if only one sample is specified.
- ncol
Number of columns if facetting.
- colGeometryName
Name of a
colGeometry
sf
data frame whose numeric columns of interest are to be used to compute the metric. UsecolGeometryNames
to look up names of thesf
data frames associated with cells/spots.- annotGeometryName
Name of a
annotGeometry
of the SFE object, to annotate the gene expression plot.- reducedDimName
Name of a dimension reduction, can be seen in
reducedDimNames
.colGeometryName
andannotGeometryName
have precedence overreducedDimName
.- ptype
Plot type, one of "density", "histogram", or "freqpoly".
- swap_rownames
Column name of
rowData(object)
to be used to identify features instead ofrownames(object)
when labeling plot elements. If not found inrowData
, then rownames of the gene count matrix will be used.- name
Name under which the Monte Carlo results are stored, which defaults to "moran.mc". For Geary's C Monte Carlo, the default is "geary.mc".
- ...
Other arguments passed to
geom_density
,geom_histogram
, orgeom_freqpoly
, depending onptype
.
Examples
library(SpatialFeatureExperiment)
library(SFEData)
sfe <- McKellarMuscleData("small")
#> see ?SFEData and browseVignettes('SFEData') for documentation
#> loading from cache
colGraph(sfe, "visium") <- findVisiumGraph(sfe)
sfe <- colDataUnivariate(sfe, type = "moran.mc", "nCounts", nsim = 100)
plotMoranMC(sfe, "nCounts")