Skip to contents

Plot NMF program usage on dimension reduction coordinates (UMAP, PCA, etc.) with flexible color mapping and customization options.

Usage

vizDimRed(
  x,
  dimred = "UMAP",
  nmf_name = "NMF",
  program = 1,
  point_size = 0.8,
  alpha = 1,
  color_scale = "viridis",
  title = NULL,
  dims = c(1, 2)
)

Arguments

x

A SingleCellExperiment object with NMF results and dimension reduction

dimred

Character, name of dimension reduction to use (default "UMAP")

nmf_name

Character, name of NMF result to use (default "NMF")

program

Character or integer, which NMF program to plot (e.g., "NMF_1", "NMF_4", or 4)

point_size

Numeric, size of points (default 0.8)

alpha

Numeric, transparency of points (default 1.0)

color_scale

Character, color scale to use: "viridis", "plasma", "inferno", "magma", or custom (default "viridis")

title

Character, plot title (if NULL, auto-generates from program name)

dims

Integer vector of length 2, which dimensions to plot (default c(1,2))

Value

A ggplot object

Examples

# Basic usage
library(scuttle)
sce <- mockSCE()
sce <- logNormCounts(sce)
sce <- runNMFscape(sce, k = 5)
#> Running NMF with k=5 factors...
#> 
#> iter |      tol 
#> ---------------
#>    1 | 8.10e-01
#>    2 | 4.09e-02
#>    3 | 1.84e-02
#>    4 | 9.90e-03
#>    5 | 6.27e-03
#>    6 | 4.41e-03
#>    7 | 3.29e-03
#>    8 | 2.52e-03
#>    9 | 1.92e-03
#>   10 | 1.47e-03
#>   11 | 1.13e-03
#>   12 | 8.68e-04
#>   13 | 6.67e-04
#>   14 | 5.15e-04
#>   15 | 4.01e-04
#>   16 | 3.06e-04
#>   17 | 2.38e-04
#>   18 | 1.85e-04
#>   19 | 1.46e-04
#>   20 | 1.18e-04
#>   21 | 9.48e-05
#>   22 | 7.74e-05
#>   23 | 6.41e-05
#>   24 | 5.35e-05
#>   25 | 4.53e-05
#>   26 | 3.83e-05
#>   27 | 3.29e-05
#>   28 | 2.82e-05
#>   29 | 2.43e-05
#>   30 | 2.11e-05
#>   31 | 1.86e-05
#>   32 | 1.64e-05
#>   33 | 1.45e-05
#>   34 | 1.30e-05
#>   35 | 1.17e-05
#>   36 | 1.05e-05
#>   37 | 9.55e-06
#> NMF completed. Results stored in reducedDim(x, 'NMF')
#> Basis matrix stored in metadata(x)$NMF_basis
sce <- runUMAP(sce)
#> Error in runUMAP(sce): could not find function "runUMAP"

# Plot NMF program 1 on UMAP
vizDimRed(sce, program = 1)
#> Error in vizDimRed(sce, program = 1): Dimension reduction 'UMAP' not found in reducedDims(x). Available: NMF

# Plot specific program by name
vizDimRed(sce, program = "NMF_4")
#> Error in vizDimRed(sce, program = "NMF_4"): Dimension reduction 'UMAP' not found in reducedDims(x). Available: NMF

# Use PCA instead of UMAP
sce <- runPCA(sce)
#> Error in runPCA(sce): could not find function "runPCA"
vizDimRed(sce, dimred = "PCA", program = 2)
#> Error in vizDimRed(sce, dimred = "PCA", program = 2): Dimension reduction 'PCA' not found in reducedDims(x). Available: NMF