Skip to contents

Calculate Eigen-correlations from a geneda object and plot a publication-quality heatmap using ggplot2 with numeric labels and significance stars. For continuous variables, Pearson correlation is used. P values follow this convention: p < 0.001, p < 0.01, p < 0.05 = three, two, one stars, respectively.

Two-level categorical variables are coded by factor level order, so the sign of the correlation follows the level order. Categorical variables with more than two levels are summarized by the multiple correlation R (the square root of R^2 from a one-way linear model, score ~ variable). R is unsigned (0 to 1) and its p-value comes from the model F-test, so results do not depend on how levels are labelled. Variables that cannot be tested (a single level, constant values, or no residual degrees of freedom, e.g. a sample ID column) are dropped.

Requires PCA scores in DimReduction(object); does not recompute PCA.

Usage

PlotEigenCorr(object, num_pcs = 10, meta_cols = NULL)

Arguments

object

A geneda object containing normalized and metadata, and optionally DimReduction scores.

num_pcs

Number of principal components to correlate.

meta_cols

Optional character vector of metadata column names to include. Defaults to all metadata columns.

Value

A list with elements: cor_matrix, pval_matrix, stars, plot (ggplot)

Examples

data(Snail1KO)
counts <- as.matrix(Snail1KO$rawCounts)
counts <- counts[rowSums(counts >= 10) >= 3, ]
meta <- Snail1KO$metadata
rownames(meta) <- meta$Sample
norm <- log2(t(t(counts) / colSums(counts)) * 1e6 + 1)
obj <- GenEDA(normalized = norm, metadata = meta, counts = counts)
obj <- FindVariableFeatures(obj, nfeatures = 1000)
obj <- RunPCA(obj)
#> Calculating principal components from top 1000 HVGs
#> Percent variations:
#> PC1: 88.56 %
#> PC2: 5.9 %
#> PC3: 2.91 %
#> PC4: 1.55 %
#> PC5: 1.08 %
#> PC6: 0 %
ec <- PlotEigenCorr(obj, num_pcs = 5, meta_cols = "Genotype")
ec$plot