distErrorPlot {SpatialDDLS}R Documentation

Generate box or violin plots showing error distribution

Description

Generate box or violin plots to show how errors are distributed. Errors can be shown all mixed or either split by cell type (CellType) or number of cell types present in the spots (nCellTypes). See the facet.by argument and examples for more details.

Usage

distErrorPlot(
  object,
  error,
  colors,
  x.by = "pBin",
  facet.by = NULL,
  color.by = "nCellTypes",
  filter.sc = TRUE,
  error.label = FALSE,
  pos.x.label = 4.6,
  pos.y.label = NULL,
  size.point = 0.1,
  alpha.point = 1,
  type = "violinplot",
  ylimit = NULL,
  nrow = NULL,
  ncol = NULL,
  title = NULL,
  theme = NULL,
  ...
)

Arguments

object

SpatialDDLS object with trained.model slot containing metrics in the test.deconv.metrics slot of a DeconvDLModel object.

error

Error to be represented. Available metric errors are: absolute error ('AbsErr'), proportional absolute error ('ppAbsErr'), squared error ('SqrErr'), and proportional squared error ('ppSqrErr').

colors

Vector of colors to be used.

x.by

Variable used for the X-axis. When facet.by is not NULL, the best choice is pBin (probability bins). Options: nCellTypes (number of different cell types), CellType (cell type), and pBin.

facet.by

Show data in different panels. Options are nCellTypes (number of different cell types) and CellType (cell type) (NULL by default).

color.by

Variable used to color data. Options are nCellTypes and CellType.

filter.sc

Boolean indicating whether single-cell profiles are filtered out and only mixed transcriptional profile errors are shown (TRUE by default).

error.label

Boolean indicating whether to show the average error as a plot annotation (FALSE by default).

pos.x.label

X-axis position of error annotations.

pos.y.label

Y-axis position of error annotations.

size.point

Size of points (0.1 by default).

alpha.point

Alpha of points (0.1 by default).

type

Type of plot: 'boxplot' or 'violinplot' (the latter by default).

ylimit

Upper limit in Y-axis if it is required (NULL by default).

nrow

Number of rows if facet.by is not NULL.

ncol

Number of columns if facet.by is not NULL.

title

Title of the plot.

theme

ggplot2 theme.

...

Additional arguments for the facet_wrap function of ggplot2 if facet.by is not NULL.

Value

A ggplot object.

See Also

calculateEvalMetrics corrExpPredPlot blandAltmanLehPlot barErrorPlot

Examples


set.seed(123)
sce <- SingleCellExperiment::SingleCellExperiment(
  assays = list(
    counts = matrix(
      rpois(30, lambda = 5), nrow = 15, ncol = 20,
      dimnames = list(paste0("Gene", seq(15)), paste0("RHC", seq(20)))
    )
  ),
  colData = data.frame(
    Cell_ID = paste0("RHC", seq(20)),
    Cell_Type = sample(
      x = paste0("CellType", seq(6)), size = 20, replace = TRUE
    )
  ),
  rowData = data.frame(
    Gene_ID = paste0("Gene", seq(15))
  )
)
SDDLS <- createSpatialDDLSobject(
  sc.data = sce,
  sc.cell.ID.column = "Cell_ID",
  sc.gene.ID.column = "Gene_ID",
  sc.filt.genes.cluster = FALSE
)
SDDLS <- genMixedCellProp(
  object = SDDLS,
  cell.ID.column = "Cell_ID",
  cell.type.column = "Cell_Type",
  num.sim.spots = 50,
  train.freq.cells = 2/3,
  train.freq.spots = 2/3,
  verbose = TRUE
)
SDDLS <- simMixedProfiles(SDDLS)
# training of DDLS model
SDDLS <- trainDeconvModel(
  object = SDDLS,
  batch.size = 15,
  num.epochs = 5
)
# evaluation using test data
SDDLS <- calculateEvalMetrics(object = SDDLS)
# representation, for more examples, see the vignettes
distErrorPlot(
  object = SDDLS,
  error = "AbsErr",
  facet.by = "CellType",
  color.by = "nCellTypes",
  error.label = TRUE
)
distErrorPlot(
  object = SDDLS,
  error = "AbsErr",
  x.by = "CellType",
  facet.by = NULL,
  color.by = "CellType",
  error.label = TRUE
)



[Package SpatialDDLS version 1.0.2 Index]