Introduction
This vignette demonstrates how to visualize clustering results from recall and compare them with standard Seurat clustering.
Data Preparation
# Load your Seurat object
# seurat_obj <- readRDS("your_data.rds")
# Standard preprocessing
seurat_obj <- NormalizeData(seurat_obj)
seurat_obj <- FindVariableFeatures(seurat_obj, nfeatures = 2000)
seurat_obj <- ScaleData(seurat_obj)
seurat_obj <- RunPCA(seurat_obj)
seurat_obj <- FindNeighbors(seurat_obj, dims = 1:10)
seurat_obj <- RunUMAP(seurat_obj, dims = 1:10)Comparing Clustering Methods
Standard vs Calibrated Clustering
# Standard Seurat clustering
seurat_standard <- FindClusters(seurat_obj, resolution = 0.8)
# recall calibrated clustering
seurat_recall <- FindClustersRecall(seurat_obj, resolution_start = 0.8)Side-by-Side UMAP Comparison
p1 <- DimPlot(seurat_standard, reduction = "umap", label = TRUE, pt.size = 0.5) +
ggtitle(paste0("Standard Seurat (", length(unique(Idents(seurat_standard))), " clusters)")) +
theme(legend.position = "none")
p2 <- DimPlot(seurat_recall, reduction = "umap", label = TRUE, pt.size = 0.5) +
ggtitle(paste0("recall Calibrated (", length(unique(Idents(seurat_recall))), " clusters)")) +
theme(legend.position = "none")
p1 + p2Cluster Quality Assessment
Cluster Size Distribution
# Extract cluster information
standard_clusters <- table(Idents(seurat_standard))
recall_clusters <- table(Idents(seurat_recall))
# Create data frames
df_standard <- data.frame(
Cluster = names(standard_clusters),
Count = as.numeric(standard_clusters),
Method = "Standard"
)
df_recall <- data.frame(
Cluster = names(recall_clusters),
Count = as.numeric(recall_clusters),
Method = "recall"
)
df_combined <- rbind(df_standard, df_recall)
# Plot
ggplot(df_combined, aes(x = reorder(Cluster, -Count), y = Count, fill = Method)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Method, scales = "free_x") +
labs(x = "Cluster", y = "Number of Cells", title = "Cluster Size Distribution") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))Marker Gene Heatmap
# Find markers for recall clusters
recall_markers <- FindAllMarkers(
seurat_recall,
only.pos = TRUE,
min.pct = 0.25,
logfc.threshold = 0.25
)
# Select top 5 markers per cluster
top_markers <- recall_markers %>%
dplyr::group_by(cluster) %>%
dplyr::top_n(n = 5, wt = avg_log2FC)
# Create heatmap
DoHeatmap(seurat_recall, features = top_markers$gene) +
scale_fill_gradientn(colors = c("blue", "white", "red")) +
ggtitle("Top Marker Genes per Cluster (recall)")Feature Visualization
Expression Patterns
# Define marker genes for your cell types
markers <- c("CD3D", "CD14", "MS4A1", "CD8A", "FCGR3A", "NKG7")
# Feature plots
FeaturePlot(seurat_recall, features = markers, ncol = 3)Resolution Analysis
Multi-Resolution Comparison
resolutions <- c(0.4, 0.8, 1.2)
plots <- list()
for (res in resolutions) {
seurat_temp <- FindClustersRecall(seurat_obj, resolution_start = res)
n_clusters <- length(unique(Idents(seurat_temp)))
plots[[as.character(res)]] <- DimPlot(seurat_temp, label = TRUE, pt.size = 0.3) +
ggtitle(paste0("Resolution: ", res, " (", n_clusters, " clusters)")) +
theme(legend.position = "none")
}
wrap_plots(plots, ncol = 3)Publication-Ready Figures
Custom Theme
theme_publication <- function() {
theme_minimal() +
theme(
plot.title = element_text(size = 14, face = "bold", hjust = 0.5),
axis.title = element_text(size = 12),
axis.text = element_text(size = 10),
legend.title = element_text(size = 11),
legend.text = element_text(size = 10),
panel.grid.minor = element_blank(),
panel.border = element_rect(color = "black", fill = NA, linewidth = 0.5)
)
}