plotSilhouette: Plot distribution of approximate silhouette widths

View source: R/func_sc.R

plotSilhouetteR Documentation

Plot distribution of approximate silhouette widths

Description

This function creates a violin scatter plot to show the distribution of the approximate silhouette width across cells in each cluster.

Usage

plotSilhouette(
  object,
  clusters,
  printDiff = TRUE,
  plot = TRUE,
  cluster_color = NULL,
  point_size = 2,
  point_alpha = 0.8,
  point_shape = 16,
  swarm_method = "quasirandom",
  add_mean = TRUE,
  mean_color = "firebrick",
  mean_size = 1,
  theme_size = 18
)

Arguments

object

A numeric matrix-like object containing observations in rows and variables in columns.

clusters

A vector of length equal to ncol(object), indicating the cluster assigned to each observation.

printDiff

Logical scalar indicating whether to print the precentage of cells assigned to different cluster(s). Default is TRUE.

plot

Logical scalar indicating whether to draw the plot. Default is TRUE.

cluster_color

A character vector of color codes indicating the colour of the clusters. Default is NULL, and use choosePalette() to select a palette.

point_size

A numeric scalar indicating the size of the points. Default is 2.

point_alpha

A numeric scalar (between 0 and 1) indicating the transparency. Default is 0.8.

point_shape

An integer scalar (between 0 and 25) indicating the shape aesthetics. Default is 16.

swarm_method

A string indicating the method for arranging points. Method recongised by ggbeeswarm are "quasirandom", "pseudorandom", "smiley" and "frowney". Default is "quasirandom".

add_mean

Logical scalar indicating whether add a horizontal reference line at mean silhouette width. Default is TRUE.

mean_color

A string indicating the colour of the reference line. Default is "firebrick".

mean_size

A numeric scalar indicating the size of the reference line. Default is 1.

theme_size

A numeric scalar indicating the base font size. Default is 18.

Details

The function uses approxSilhouette() from the bluster package' to calculate the silhouette widths using an approximate approach. Using the information stored in the returned DataFrame, it:

  • prints the descriptive statistics of approximate silhouette widths.

  • calculates the percentage of cells assigned to the closest cluster and prints the result when printDiff = TRUE.

  • creates a violin scatter plot to show thedistribution of the approximate silhouette width when plot = TRUE.

These information can allow users to identify poorly separate clusters quickly.

Value

A ggplot object when plot = TRUE

Author(s)

I-Hsuan Lin

See Also

bluster::approxSilhouette()

Examples

# Load demo dataset
data(sce)

mat <- SingleCellExperiment::reducedDim(sce, "PCA")
plotSilhouette(mat, sce$label)

ycl6/scRUtils documentation built on Feb. 18, 2025, 6:14 a.m.