apl_coords: Calculate Association Plot coordinates

View source: R/apl.R

apl_coordsR Documentation

Calculate Association Plot coordinates

Description

Calculates the Association Plot coordinates for either the rows, columns or both (default).

Usage

apl_coords(caobj, group, calc_rows = TRUE, calc_cols = TRUE)

Arguments

caobj

A "cacomp" object with principal row coordinates and standardized column coordinates calculated.

group

Numeric/Character. Vector of indices or column names of the columns to calculate centroid/x-axis direction.

calc_rows

TRUE/FALSE. Whether apl row coordinates should be calculated. Default TRUE.

calc_cols

TRUE/FALSE. Whether apl column coordinates should be calculated. Default TRUE.

Details

Coordinates (x,y) of row vector \vec{r} are defined as

x(\vec{r}) := \left|\vec{r}\right|\cos(\phi(\vec{r}))

y(\vec{r}) := \left|\vec{r}\right|\sin(\phi(\vec{r}))

The x-direction is determined by calculating the centroid of the columns selected with the indices in "group".

Value

Returns input "cacomp" object and adds components "apl_rows" and/or "apl_cols" for row and column coordinates. In "group" the indices of the columns used to calculate the centroid are saved.

References

Association Plots: Visualizing associations in high-dimensional correspondence analysis biplots Elzbieta Gralinska, Martin Vingron bioRxiv 2020.10.23.352096; doi: https://doi.org/10.1101/2020.10.23.352096

Examples

set.seed(1234)
# Simulate scRNAseq data
cnts <- data.frame(cell_1 = rpois(10, 5),
                   cell_2 = rpois(10, 10),
                   cell_3 = rpois(10, 20),
                   cell_4 = rpois(10, 20))
rownames(cnts) <- paste0("gene_", 1:10)
cnts <- as.matrix(cnts)

# Run correspondence analysis
ca <- cacomp(obj = cnts, princ_coords = 3)
# Calculate APL coordinates
ca <- apl_coords(ca, group = 3:4)

VingronLab/APL documentation built on Feb. 14, 2024, 11:40 a.m.