plotTernary {CytoSimplex} | R Documentation |
Create ternary plots
Description
Create ternary plots that show similarity between single cells and selected three terminals in a ternary baricentric coordinate.
Usage
plotTernary(x, ...)
## Default S3 method:
plotTernary(
x,
clusterVar,
vertices,
features = NULL,
veloGraph = NULL,
byCluster = NULL,
processed = FALSE,
method = c("euclidean", "cosine", "pearson", "spearman"),
force = FALSE,
sigma = 0.08,
scale = TRUE,
dotColor = "grey60",
returnData = FALSE,
...
)
## S3 method for class 'Seurat'
plotTernary(
x,
layer = "counts",
assay = NULL,
clusterVar = NULL,
processed = FALSE,
...
)
## S3 method for class 'SingleCellExperiment'
plotTernary(
x,
assay.type = "counts",
clusterVar = NULL,
processed = FALSE,
...
)
## S3 method for class 'simMat'
plotTernary(
x,
title = NULL,
veloMat = NULL,
nGrid = 10,
radius = 0.1,
dotSize = 0.6,
dotColor = "grey60",
labelColors = c("#3B4992FF", "#EE0000FF", "#008B45FF"),
vertexLabelSize = 5,
vertexLabelDrift = 0.03,
axisBreak = 5,
axisTextShow = TRUE,
axisTextSize = 4,
axisTextDrift = 0.02,
gridLineAlpha = 0.6,
arrowLinewidth = 0.25,
arrowAngle = 20,
arrowLen = 0.2,
titleSize = 14,
equilateral = TRUE,
margin = 0.1,
...
)
Arguments
x |
Input data. Can be a |
... |
Arguments passed to other methods. |
clusterVar |
A vector/factor assigning the cluster variable to each
column of the matrix object. For "Seurat" method, |
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 |
veloGraph |
Cell x cell |
byCluster |
Default |
processed |
Logical. Whether the input matrix is already processed.
|
method |
Similarity calculation method. Default |
force |
Whether to force calculate the similarity when more then 500
features are detected, which is generally not recommended. Default
|
sigma |
Gaussian kernel parameter that controls the effect of variance.
Only effective when using a distance metric (i.e. |
scale |
Whether to min-max scale the distance matrix by clusters.
Default |
returnData |
Logical. Whether to return similarity and aggregated
velocity data if applicable instead of generating plot. Default |
layer |
For "Seurat" method, which layer of the assay to be used.
Default |
assay |
For "Seurat" method, the specific assay to get data from.
Default |
assay.type |
For "SingleCellExperiment" methods. Which assay to use for
calculating the similarity. Default |
title |
Title text of the plot. Default |
veloMat |
Aggregated velocity matrix. Output of |
nGrid |
Number of grids along the bottom side of the equilateral
triangle. Default |
radius |
Arrow length of unit velocity. Lower this when arrows point
outside of the coordinate. Default |
dotSize , dotColor |
Dot aesthetics passed to
|
labelColors |
Colors of the axis lines and vertex labels.
Default |
vertexLabelSize , vertexLabelDrift |
Adjustment on the three vertex text
labels. Drift means the distance that the labels should be moved against the
center of the plot. Default size |
axisBreak |
Number of breaks to be labeled along axis. Default
|
axisTextShow |
Logical, whether to show axis text. Default |
axisTextSize , axisTextDrift |
Similar to the vertex adjustment applied
to the text label along the axis breaks. Default size |
gridLineAlpha |
Transparency of background grid lines. Default
|
arrowLinewidth , arrowAngle , arrowLen |
Arrow aesthetics, see Details. |
titleSize |
Size of title text. Default |
equilateral |
Logical, whether to always display the triangle as
equilateral. Default |
margin |
Margin allowed around of the triangle plotting region when
|
Details
Argument inheritance - For matrix/dgCMatrix ("default" method), we first calculate the similarity matrix and obtain a "simMat" object. Then the "simMat" method is internally called. For data container objects (e.g. Seurat), we obtain the correct data matrix first and then call the "default" method. The arguments inherits as the flow described above.
The calculation of similarity matrix - The similarity is calculated either by converting a distance metric ("euclidean" or "cosine") with Gaussian kernel, or directly computed with correlation metrics ("pearson" or "spearman"). The centroid of each terminal is obtained first, and the specified metric from each cell to each terminal is calculated. The similarity matrix (n cells by v terminals) is lastly normalized to sum to 1 for each cell, so it becomes a baricentric coordinate.
Arrow aesthetics parameters - The shape of arrows is controlled by 3
arguments. Considering an arrow as the combination of a line segment and a
triangle, arrowLinewidth
controls the width of the line as well as
the edge line of the triangle; arrowAngle
equals to angle of the
arrow-tip vertex of the triangle devided by 2 (e.g. the triangle is
equilateral when arrowAngle = 20
); arrowLen
controls the
absolute length from the arrow-tip vertex to its opposite edge.
Value
For "simMat" method, a ggplot object. For other methods, a ggplot
object when splitCluster = FALSE
, or a list of ggplot objects when
splitCluster = TRUE
.
Examples
gene <- selectTopFeatures(rnaRaw, rnaCluster, c("OS", "RE", "CH"))
plotTernary(rnaRaw, rnaCluster, c("OS", "RE", "CH"), gene)
# Seurat example
library(Seurat)
srt <- CreateSeuratObject(rnaRaw)
Idents(srt) <- rnaCluster
gene <- selectTopFeatures(srt, vertices = c("OS", "RE", "CH"))
plotTernary(srt, features = gene, vertices = c("OS", "RE", "CH"))
# SingleCellExperiment example
library(SingleCellExperiment)
sce <- SingleCellExperiment(assays = list(counts = rnaRaw))
colLabels(sce) <- rnaCluster
gene <- selectTopFeatures(sce, vertices = c("OS", "RE", "CH"))
plotTernary(sce, features = gene, vertices = c("OS", "RE", "CH"))