plot_embedding_space: Plot Embedding Space

View source: R/visualization_faces.R

plot_embedding_spaceR Documentation

Plot Embedding Space

Description

Creates a 2D visualization of face embeddings using dimensionality reduction, showing how faces cluster in the embedding space.

Usage

plot_embedding_space(
  embeddings_df,
  method = c("umap", "pca", "tsne"),
  labels = NULL,
  highlight = NULL,
  n_neighbors = 15,
  perplexity = 30
)

Arguments

embeddings_df

A tibble from batch_embeddings with an 'embedding' list column.

method

Dimensionality reduction method: "umap" (default), "pca", or "tsne".

labels

Optional character vector of labels for each point.

highlight

Optional indices of points to highlight (e.g., target position).

n_neighbors

For UMAP, number of neighbors. Default is 15.

perplexity

For t-SNE, perplexity parameter. Default is 30.

Details

This visualization helps understand:

  • How faces cluster by identity

  • Which foils are closest to the target in embedding space

  • Overall structure of similarity in a lineup

Only method = "pca" is a linear projection of the embeddings, and it still loses most of the distance in the full embedding space. Distances in UMAP and t-SNE plots are not interpretable, and with a lineup of six faces the layout from either is close to arbitrary. Use method = "pca" for a lineup, and read exact distances from lineup_similarity.

Value

A ggplot2 object.

Examples

## Not run: 
# Get embeddings for all lineup members
all_faces <- c("target.jpg", paste0("foil", 1:5, ".jpg"))
embs <- batch_embeddings(all_faces)

# Plot with target highlighted
plot_embedding_space(embs, method = "pca",
                     labels = c("Target", paste0("F", 1:5)), highlight = 1)

## End(Not run)


r4lineups documentation built on Nov. 10, 2026, 1:08 a.m.