Generate Patchwork Word Clouds for All Leiden Clusters
write_cluster_wordclouds_patchwork.RdFor each cell type in a network result list, this function creates a multi-panel word cloud figure where each panel represents one Leiden cluster. GO term labels are sized by their network degree (optionally weighted by absolute log2 fold-change) and semantically similar terms are merged via hierarchical clustering on Jaccard distance of constituent words. The combined figure is saved as a PNG file.
Usage
write_cluster_wordclouds_patchwork(
net_list,
outputDir,
comparison = "CD206_Car_vs_Bleo",
min_terms = 5,
max_terms = 50,
use_logfc_weight = FALSE,
ncol = 3,
merge_similarity = 0.6
)Arguments
- net_list
A named list of network result lists, one per cell type. Each element must be a list containing at least
go_term_df(a data frame with columnsgo_term,cluster,degree, andavg_log2FC), as returned bygenerate_overlap_network.- outputDir
Character path to the root output directory. Word cloud PNGs are saved to
<outputDir>/<comparison>/networks/.- comparison
Character string identifying the comparison (e.g.,
"CD206_Car_vs_Bleo"). Used to construct the output sub-directory.- min_terms
Integer. Minimum number of (post-merge) GO term phrases required to generate a word cloud for a cluster. Clusters with fewer terms are skipped. Default
5.- max_terms
Integer. Maximum number of GO term phrases to include per cluster word cloud (after sorting by weight). Default
50.- use_logfc_weight
Logical. If
TRUE, term weights are scaled by1 + abs(avg_log2FC), emphasizing terms backed by larger fold- changes. DefaultFALSE.- ncol
Integer. Number of columns in the patchwork grid layout. Default
3.- merge_similarity
Numeric
[0, 1]orNULL. Jaccard- distance threshold for merging semantically similar GO term labels. A value of0.6means terms sharing >= 40\ (the most frequent label is kept and frequencies are summed). Set toNULLto disable merging. Default0.6.
Output files
One PNG per cell type:
<outputDir>/<comparison>/networks/<celltype>_all_clusters_wordclouds.png