plot_residuals: Residuals plot

View source: R/scedasticity.R

plot_residualsR Documentation

Residuals plot

Description

Plots residuals from a deconvolution result object against bulk gene expression (on semi-log axis). Normal residuals, weighted residuals or Studentized residuals can be visualised to check for heteroscedasticity and genes with extreme errors.

Usage

plot_residuals(
  fit,
  test = NULL,
  type,
  show_outliers = TRUE,
  show_plot = TRUE,
  ...
)

ggplot_residuals(
  fit,
  test = NULL,
  type,
  show_outliers = TRUE,
  nlabels = 0,
  ...
)

Arguments

fit

'deconv' class deconvolution object

test

bulk gene expression matrix assumed to be in raw counts. If test is not supplied, fitted values are plotted instead.

type

Specifies type of residuals to be plotted, either "raw" for unweighted residuals, "weight" for weighted residuals, or "student" for Studentized residuals.

show_outliers

Logical whether to show any remaining outlying extreme genes in red

show_plot

Logical whether to show plot using base graphics (used to allow return of dataframe of points without plotting)

...

Optional arguments passed to plot() for the base graphics version, or to geom_text_repel() for the ggplot2 version.

nlabels

Number of outlying gene labels to add. Labels are only added if outliers are detected. Although each gene has a point for the residual for every bulk sample, only the point with the maximum absolute residual is labelled.

Value

Produces a scatter plot in base graphics. Returns invisibly a dataframe of the coordinates of the points. The ggplot version returns a ggplot2 plotting object.


cellGeometry documentation built on April 20, 2026, 1:06 a.m.