CAbiplot

CAbiplot is an R package that wraps FactoMineR and factoextra into a single, reusable pipeline for Correspondence Analysis (CA). It reproduces (as package functions) the full set of diagnostic plots from a typical CA reporting script: a scree plot, a symmetric biplot, row-only and column-only plots, row/column contribution plots, and row/column cos2 plots — plus a combined summary figure.

An example genotype-by-trait data set (19 genotypes x 6 traits) is bundled with the package.

Installation

Install the required dependencies, then install the package from source:

install.packages(c("FactoMineR", "factoextra", "ggplot2", "gridExtra"))

# From a local source tree / tarball:
install.packages("path/to/CAbiplot", repos = NULL, type = "source")

# Or, with devtools, from the unpacked package directory:
# devtools::install("path/to/CAbiplot")

Quick start

library(CAbiplot)

# Load the bundled example data (or use your own numeric matrix / data.frame
# / path to a CSV file with row names in the first column)
geno <- get_genotype_traits()

# Run the whole pipeline: fits CA, builds every plot, prints result tables,
# and saves each plot as a high-resolution JPEG in the given directory
report <- ca_report(geno, output_dir = "ca_output", prefix = "CA")

# Everything is also returned for interactive use:
report$res.ca            # the fitted FactoMineR::CA object
report$eig                # eigenvalue / inertia table
report$plots$biplot       # the symmetric biplot (ggplot object)
report$plots$combined     # the combined summary figure

Prefer to build plots one at a time, or on a CA object you already computed yourself?

res.ca <- run_ca(geno)

ca_scree_plot(res.ca)
ca_biplot(res.ca)
ca_row_plot(res.ca)
ca_col_plot(res.ca)
ca_contrib_plot(res.ca, choice = "row", axes = 1)
ca_contrib_plot(res.ca, choice = "col", axes = 2)
ca_cos2_plot(res.ca, choice = "row")
ca_cos2_plot(res.ca, choice = "col")

Functions

Function Description
read_ca_data() Read a delimited file into a numeric CA-ready data.frame
get_genotype_traits() Load the bundled example genotype-by-trait data set
run_ca() Run FactoMineR::CA() on a matrix/data.frame/file path
ca_scree_plot() Eigenvalue scree plot
ca_biplot() Symmetric row + column biplot
ca_row_plot() Row-only plot
ca_col_plot() Column-only plot
ca_contrib_plot() Row or column contribution plot for chosen dimension(s)
ca_cos2_plot() Row or column cos2 (quality of representation) plot
ca_report() Full pipeline: fit, plot everything, save, print tables

Tests

Run the test suite with:

devtools::test()
# or
testthat::test_dir("tests/testthat")

License

MIT