plotDeltaDistribution: Plot delta distributions

View source: R/plotDeltaDistribution.R

plotDeltaDistributionR Documentation

Plot delta distributions


Plot the distribution of deltas (i.e., the gap between the assignment score for the assigned label and those of the remaining labels) across cells assigned to each reference label.


  show = c("", ""),
  labels.use = colnames(results$scores),
  references = NULL,
  chosen.only = TRUE,
  size = 2,
  ncol = 5, = TRUE,
  this.color = "#000000",
  pruned.color = "#E69F00",
  grid.vars = list()



A DataFrame containing the output from SingleR, classifySingleR, combineCommonResults, or combineRecomputedResults.


String specifying whether to show the difference from the median ("") or the difference from the next-best score ("").


Character vector specifying the labels to show in the plot facets. Defaults to all labels in results.


Integer scalar or vector specifying the references to visualize. This is only relevant for combined results, see Details.


Logical scalar indicating whether to only show deltas for individual labels that were chosen as the final label in a combined result.


Numeric scalar to set the size of the dots.


Integer scalar to set the number of labels to display per row.

Logical scalar specifying whether cell dots should be plotted on top of the violin plots.


String specifying the color for cells that were assigned to the label.


String specifying the color for cells that were assigned to the label but pruned.


Named list of extra variables to pass to grid.arrange, used to arrange the multiple plots generated when references is of length greater than 1.


This function creates jitter and violin plots showing the deltas for all cells across one or more labels. The idea is to provide a visual diagnostic for the confidence of assignment of each cell to its label. The show argument determines what values to show on the y-axis:

  • "", the difference between the score of the assigned label and the median of all scores for each cell.

  • "", the difference between best and second-best scores of each cell at the last round of fine-tuning.

If any fine-tuning was performed, the highest scoring label for an individual cell may not be its final label. This may manifest as negative values when show="". show="" is guaranteed to be positive but may be overly stringent for references involving very similar labels.

Pruned calls are identified as NAs in the pruned.labels field in results. Points corresponding to cells with pruned calls are colored by pruned.color; this can be disabled by setting pruned.color=NA.

For combined results (see ?combineRecomputedResults), this function will show the deltas faceted by the assigned label within each individual reference. The references to show in this manner can be specified using the references argument, entries of which refer to columns of results$orig.results.

By default, a separate plot is created for each individual reference in a combined results. Deltas are only shown in each plot if the label in the corresponding reference was chosen as the overall best label in the combined results. However, this can be changed to show all deltas for an individual reference by setting chosen.only=FALSE.


If references specifies a single set of deltas, a ggplot object is returned showing the deltas in violin plots.

If references specifies multiple deltas for a combined result, multiple ggplot objects are generated in a grid on the current graphics device.

If delta.use specifies multiple deltas and grid.vars is set to NULL, a list is returned containing the ggplot objects for manual display.


Daniel Bunis and Aaron Lun

See Also

pruneScores, to remove low-quality labels based on the scores.

plotScoreDistribution and plotScoreHeatmap, for alternative diagnostic plots.


example(SingleR, echo=FALSE)

# Showing the delta to the median:

# Showing the delta to the next-highest score:
plotDeltaDistribution(pred, show = "")

# Multi-reference compatibility:
example(combineRecomputedResults, echo = FALSE)

plotDeltaDistribution(results = combined)

plotDeltaDistribution(results = combined, chosen.only=FALSE)

# Tweaking the grid controls:
plotDeltaDistribution(combined, grid.vars = list(ncol = 2))

LTLA/SingleR documentation built on Sept. 17, 2023, 6:51 p.m.