Skip to contents

Draw lines between cluster centroids on embedding space based on confusion matrix values. This visualizes which clusters are frequently confused.

Usage

plot_cluster_links(
  embeddings,
  labels,
  confusion_matrix,
  threshold = 0,
  line_color = "#ffa500",
  line_scale = 10,
  show_labels = TRUE,
  label_size = 4,
  point_color = "white",
  point_size = 5,
  point_alpha = 0.7,
  add_to_plot = NULL
)

Arguments

embeddings

Matrix of 2D embeddings (cells x 2), e.g., UMAP or t-SNE coordinates

labels

Cluster labels for each cell

confusion_matrix

Confusion/connection matrix between clusters (e.g., R1-normalized)

threshold

Only draw lines for values above this threshold (default: 0)

line_color

Color for connection lines (default: "#ffa500", orange)

line_scale

Scale factor for line width (default: 10)

show_labels

Show cluster labels at centroids (default: TRUE)

label_size

Size of cluster labels (default: 4)

point_color

Color for centroid points (default: "white")

point_size

Size of centroid points (default: 5)

point_alpha

Transparency of centroid points (default: 0.7)

add_to_plot

If provided, add to existing ggplot object

Value

A ggplot2 object showing cluster connections

Details

This function computes the median position (centroid) of each cluster in the embedding space, then draws lines between centroids where the confusion matrix value exceeds the threshold. Line width is proportional to the confusion value.

Examples

if (FALSE) { # \dontrun{
# Get UMAP coordinates from Seurat object
embeddings <- Seurat::Embeddings(seurat_obj, "umap")
labels <- seurat_obj$seurat_clusters

# Run assessment and get R1 matrix
result <- sc_assessment(X, labels)

# Plot connections
plot_cluster_links(embeddings, labels, result$r1_normalized, threshold = 0.1)
} # }