Combined plot showing cells colored by cluster with confusion-based connections
Usage
plot_embedding_with_links(
embeddings,
labels,
confusion_matrix,
threshold = 0.1,
title = NULL,
colors = NULL,
point_size = 0.5,
line_color = "#ffa500",
line_scale = 10,
show_legend = TRUE
)Arguments
- embeddings
Matrix of 2D embeddings (cells x 2)
- labels
Cluster labels for each cell
- confusion_matrix
Confusion matrix between clusters
- threshold
Threshold for drawing connection lines (default: 0.1)
- title
Plot title
- colors
Optional color palette for clusters
- point_size
Size of cell points (default: 0.5)
- line_color
Color for connection lines (default: "#ffa500")
- line_scale
Scale factor for line widths (default: 10)
- show_legend
Show cluster legend (default: TRUE)
Details
This function creates a scatter plot of cells colored by cluster assignment, with lines connecting cluster centroids based on confusion matrix values. Useful for visualizing which clusters are transcriptionally similar and frequently confused by the classifier.
Examples
if (FALSE) { # \dontrun{
# With Seurat object
embeddings <- Seurat::Embeddings(seurat_obj, "umap")
labels <- seurat_obj$seurat_clusters
result <- sc_assessment(GetAssayData(seurat_obj), labels)
plot_embedding_with_links(
embeddings, labels, result$r1_normalized,
threshold = 0.1, title = "UMAP with Confusion Links"
)
} # }