jj_cluster_correlation_heatmap: encirle fraction of points that contain x percent of the...

View source: R/jj_cell_similarity.R

jj_cluster_correlation_heatmapR Documentation

encirle fraction of points that contain x percent of the density mass

Description

Option 1: plot correlations between clusters of cells based on values from one matrix (eg. scaled scRNA matrix with cells from 3 different clusters) Option 2: plot correlations between clusters of cells based on common features from two matrices (eg. scaled scRNA matrix with 3 groups and scaled gene activity matrix with 6 groups) Additional arguments can be passed to Heatmap function such as cluster_rows=FALSE, name = 'Spearman_cor', row_title = row_title, column_title = 'mat_b_group'

Usage

jj_cluster_correlation_heatmap(
  scaled_mat_a,
  group_a,
  scaled_mat_b = NULL,
  group_b = NULL,
  plot_complex_heatmap = TRUE,
  label = TRUE,
  plot_triangular = FALSE,
  ...
)

Arguments

scaled_mat_a

scaled gene expression/activity matrices with cells as columns and rownames (genes)

group_a

vector of the same length as columns in scaled_mat_a that defines the groups to summarize by

scaled_mat_b

optional second scaled matrix (for option 2)

group_b

vector of the same length as columns in scaled_mat_b that defines the groups to summarize by

plot_complex_heatmap

if TRUE, plot the correlation matrix as ComplexHeatmap instead of returning it

label

if TRUE, add text of Spearman correlation for each comparison

plot_triangular

if TRUE, plot a triangular heatmap without clustering (only for option 1)

rname

optional row title

Value

Returns ComplexHeatmap of Spearman correlations between the groups

Examples


#Option 1: Compare correlation of graph-based clusters based on RNA counts
pbmc_small = ScaleData(pbmc_small, features = rownames(pbmc_small))
scaled_rna = GetAssayData(pbmc_small, assay='RNA', slot='scale.data')
jj_cluster_correlation_heatmap(scaled_mat_a = scaled_rna,
                              group_a = as.character(pbmc_small$RNA_snn_res.1))
jj_cluster_correlation_heatmap(scaled_mat_a = scaled_rna,
                              group_a = as.character(pbmc_small$RNA_snn_res.1),
                              plot_triangular=TRUE)
#Option2: Dummy example, the idea is to compare clusters from a second dataset                              
pbmc_subset = pbmc_small[sample(1:nrow(pbmc_small), 100, replace = F), sample(1:ncol(pbmc_small), 50, replace = F)]
pbmc_subset = ScaleData(pbmc_subset, features = rownames(pbmc_subset))
scaled_rna2 = GetAssayData(pbmc_subset, assay='RNA', slot='scale.data')
jj_cluster_correlation_heatmap(scaled_mat_a = scaled_rna,
                              group_a = as.character(pbmc_small$RNA_snn_res.1),
                              scaled_mat_b = scaled_rna2,
                              group_b = as.character(pbmc_subset$RNA_snn_res.1))

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.