Skip to contents

Create quaternary plots that show similarity between single cells and selected four terminals in a baricentric coordinate.

See plotTernary for more details on methodologies.

A dynamic rotating view in a GIF image file can be created with writeQuaternaryGIF. Package magick must be installed in advance. Linux users may refer to this installation guide.

Usage

# S3 method for SingleCellExperiment
plotQuaternary(
  x,
  assay.type = "counts",
  clusterVar = NULL,
  processed = FALSE,
  dotColorBy = NULL,
  legendTitle = NULL,
  ...
)

Arguments

x

A SingleCellExperiment object

assay.type

Assay to use for calculating the similarity. Default "counts".

clusterVar

A variable name in colData(x). Default NULL uses colLabels(x).

processed

Logical. Whether the input matrix is already processed. TRUE will bypass internal preprocessing and input matrix will be directly used for similarity calculation. Default FALSE and raw count input is recommended. If missing in call, using slot = "counts" in "Seurat" method or using assay.type = "counts" in "SingleCellExperiment" method will force this argument to be FALSE and others for TRUE.

dotColorBy

A vector/factor for coloring dots, can be either categorical (must be character or factor) or continuous. Default NULL.

legendTitle

Title on the legend/colorbar. Default NULL uses "cluster" if dotColorBy is missing (default); user-end variable expression if dotColorBy is directly specified from plotQuaternary.default method; variable name if dotColorBy is specified from Seurat or SingleCellExperiment method.

...

Arguments passed on to plotQuaternary.default, plotQuaternary.simMat

vertices

Vector of three unique cluster names that will be used for plotting. Or a named list that groups clusters as three terminal vertices. There must not be any overlap between groups.

features

Valid matrix row subsetting index to select features for similarity calculation. Default NULL uses all available features.

byCluster

Default NULL to generate one plot with all cells. Set "all" to split cells in plot by cluster and returns a list of subplots for each cluster as well as the plot including all cells. Otherwise, a vector of cluster names to generate a list of subplots for the specified clusters.

veloGraph

Cell x cell dgCMatrix object containing velocity information. Shows velocity grid-arrow layer when specified. Default NULL does not show velocity.

method

Similarity calculation method. Default "euclidean". Choose from "euclidean", "cosine", "pearson", "spearman".

force

Whether to force calculate the similarity when more then 500 features are detected, which is generally not recommended. Default FALSE.

sigma

Gaussian kernel parameter that controls the effect of variance. Only effective when using a distance metric (i.e. method is "euclidian" or "cosine"). Larger values tighten the dot spreading on figure. Default 0.05.

scale

Whether to min-max scale the distance matrix by clusters. Default TRUE.

dotColor

Character vector of color codes. When dotColorBy is NULL, use one or as many colors as the number of cells. If dotColorBy is categorical, specify as many colors as the number of categories in dotColorBy or ggplot2 categorical color palette is used by default. If dotColorBy is continuous, specify together with breaks argument.

palette

Color palette to use when dotColorBy is given. Default "D" (viridis) for continuous value and ggplot2 default for categorical value. See detail for alternatives.

direction

Sets the order of colors in the scale. Default 1 orders as palette default. If -1, the order of colors is reversed.

breaks

Number of breaks for continuous color scale passed to non-interactive "plot3D::scatter3D" call. Default NULL.

returnData

Logical. Whether to return similarity and aggregated velocity data if applicable instead of generating plot. Default FALSE.

nGrid

Number of grids along the x-axis of the tetrahedron. Default 10.

radius

Arrow length of unit velocity. Lower this when arrows point outside of the tetrahedron. Default 0.2.

dotSize

Size of each dot. Default 0.6 for static figure, and 4 for interactive view.

labelColors

Colors of the vertex labels. Default c("#3B4992FF", "#EE0000FF", "#008B45FF", "#631879FF") (blue, red, green and purple).

arrowLinewidth

Arrow aesthetics. Default 1.6 for interactive view, 0.6 for static figure.

arrowAngle,arrowLen

Arrow aesthetics passed to TODOOOO grid::arrow. The length of the arrow will be internally converted to unit onject in inches. Default 20 and 0.1.

edgeLinewidth

Controls the linewidth of the edges of the tetrahedron. Default 1.

vertexLabelSize

Numeric, size of vertex text label relative to default size. Default 1.

title

Title text of the plot. Default NULL.

titleSize,titleColor

Setting on the main title text. Default 1, and "black".

theta,phi

Numeric scalar. The angles defining the viewing direction. theta gives the azimuthal direction and phi the colatitude. Default 20 and 0.

interactive

Logical. Whether to display plotly interactive view. Default TRUE.

Value

By default, a "plotly" object. When interactive = FALSE, a "quatPlot" object when byCluster is not specified, or a "list" of "quatPlot" objects when byCluster is specified. When returnData = TRUE, a list of similarity matrix and aggregated velocity matrix is returned.

See also

Other plotQuaternary: plotQuaternary(), plotQuaternary.Seurat()

Examples

# \donttest{
# SingleCellExperiment example
if (requireNamespace("SingleCellExperiment", quietly = TRUE)) {
  require(SingleCellExperiment)
  sce <- SingleCellExperiment(assays = list(counts = rnaRaw))
  colLabels(sce) <- rnaCluster
  gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH", "ORT"))
  plotQuaternary(sce, features = gene,
                 vertices = c("OS", "RE", "CH", "ORT"))
}
#> Selected 30 features for "CH".
#> Selected 30 features for "ORT".
#> Selected 30 features for "OS".
#> Selected 30 features for "RE".
# }