Package {CAbiplot}


Type: Package
Title: Correspondence Analysis Biplots and Diagnostic Reports
Version: 0.1.0
Description: A convenience wrapper around 'FactoMineR' and 'factoextra' for running Correspondence Analysis (CA) on a numeric data table (e.g. a genotype-by-trait or contingency-style matrix) and producing a full set of publication-ready diagnostic plots: scree plot, symmetric biplot, row-only and column-only plots, row/column contribution plots, and row/column cos2 (quality-of-representation) plots. A single top-level function runs the whole pipeline, prints formatted result tables, and optionally saves every plot as a high-resolution image, mirroring a typical CA reporting workflow used in agronomy and plant-breeding studies. An example genotype-by-trait data set is included.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 3.5.0)
Imports: FactoMineR, factoextra, ggplot2, gridExtra, utils
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2026-09-15 07:00:02 UTC; iasri
Author: Prakash Kumar [aut, cre], Himadri Sekhar Roy [aut], Ranjit Kumar Paul [aut], Md. Yeasin [aut], Sunil Kumar Yadav [aut], Amrit Kumar Paul [aut]
Maintainer: Prakash Kumar <prakash289111@gmail.com>
Repository: CRAN
Date/Publication: 2026-09-24 15:00:08 UTC

CAbiplot: Correspondence Analysis Biplots and Diagnostic Reports

Description

Provides a convenience wrapper around FactoMineR and factoextra for running Correspondence Analysis (CA) on a numeric data table and producing a full set of publication-ready diagnostic plots.

Main functions

read_ca_data

Read a delimited text file into a numeric data.frame ready for CA.

get_genotype_traits

Load the bundled example genotype-by-trait data set.

run_ca

Run CA on a data table or file path.

ca_scree_plot, ca_biplot, ca_row_plot, ca_col_plot, ca_contrib_plot, ca_cos2_plot

Build the individual diagnostic plots.

ca_report

Run the whole pipeline end to end, optionally saving every plot and printing formatted result tables.


Symmetric CA biplot (rows and columns)

Description

Symmetric CA biplot (rows and columns)

Usage

ca_biplot(res.ca, axes = c(1, 2), col.row = "#1F4E79",
  col.col = "#B22222", ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

axes

Length-2 integer vector of the dimensions to plot. Defaults to c(1, 2).

col.row

Color for row points/labels. Defaults to "#1F4E79".

col.col

Color for column points/labels. Defaults to "#B22222".

...

Additional arguments passed to fviz_ca_biplot.

Value

A ggplot object.


CA column-only plot

Description

CA column-only plot

Usage

ca_col_plot(res.ca, axes = c(1, 2), col.col = "#B22222", ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

axes

Length-2 integer vector of the dimensions to plot. Defaults to c(1, 2).

col.col

Color for column points/labels. Defaults to "#B22222".

...

Additional arguments passed to fviz_ca_col.

Value

A ggplot object.


Row or column contribution plot

Description

Row or column contribution plot

Usage

ca_contrib_plot(res.ca, choice = c("row", "col"), axes = 1, top = NULL, ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

choice

Either "row" or "col".

axes

Integer vector of dimension(s) to sum contributions over. Defaults to 1.

top

Number of rows/columns to display. Defaults to all of them.

...

Additional arguments passed to fviz_contrib.

Value

A ggplot object.


Row or column cos2 (quality of representation) plot

Description

Row or column cos2 (quality of representation) plot

Usage

ca_cos2_plot(res.ca, choice = c("row", "col"), axes = 1:2, top = NULL, ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

choice

Either "row" or "col".

axes

Integer vector of dimension(s) to sum cos2 over. Defaults to 1:2.

top

Number of rows/columns to display. Defaults to all of them.

...

Additional arguments passed to fviz_cos2.

Value

A ggplot object.


Run a full Correspondence Analysis report

Description

End-to-end pipeline that runs Correspondence Analysis on data and produces the full battery of diagnostic plots used in the package vignette: a scree plot, a symmetric biplot, row-only and column-only plots, row and column contribution plots (dimensions 1 and 2), row and column cos2 plots, and a combined summary figure. Optionally saves every plot as a high-resolution JPEG and prints formatted result tables to the console, mirroring a typical CA reporting workflow.

Usage

ca_report(data, output_dir = ".", prefix = "CA", save_plots = TRUE,
  dpi = 600, verbose = TRUE)

Arguments

data

A numeric matrix, numeric data.frame, a path to a delimited text file, or an already-computed object of class "CA".

output_dir

Directory where plots are saved when save_plots = TRUE. Created if it does not already exist. Defaults to the current working directory.

prefix

File name prefix used for saved plots. Defaults to "CA".

save_plots

Logical; save each plot as a JPEG in output_dir? Defaults to TRUE.

dpi

Resolution (dots per inch) used when saving plots. Defaults to 600.

verbose

Logical; print formatted result tables (eigenvalues, coordinates, contributions, cos2) to the console? Defaults to TRUE.

Value

Invisibly, a list with elements:

res.ca

The fitted "CA" object.

eig

Eigenvalue/inertia table from get_eigenvalue.

plots

A named list of the individual ggplot objects (scree, biplot, row, col, contrib_row_dim1, contrib_row_dim2, contrib_col_dim1, contrib_col_dim2, cos2_row, cos2_col) plus combined, a gridExtra arrangement of the scree plot, biplot, and the two dimension-1 contribution plots.

Examples


geno <- get_genotype_traits()
report <- ca_report(geno, save_plots = FALSE, verbose = FALSE)
report$plots$biplot


CA row-only plot

Description

CA row-only plot

Usage

ca_row_plot(res.ca, axes = c(1, 2), col.row = "#1F4E79", ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

axes

Length-2 integer vector of the dimensions to plot. Defaults to c(1, 2).

col.row

Color for row points/labels. Defaults to "#1F4E79".

...

Additional arguments passed to fviz_ca_row.

Value

A ggplot object.


Scree plot of CA eigenvalues

Description

Scree plot of CA eigenvalues

Usage

ca_scree_plot(res.ca, ...)

Arguments

res.ca

An object of class "CA" from run_ca or CA.

...

Additional arguments passed to fviz_eig.

Value

A ggplot object.


Load the bundled example genotype-by-trait data set

Description

Loads the example data set shipped with the package: a table of plant genotypes (rows) evaluated across six morphological/agronomic traits (columns). This is the same data used in the package vignette and examples.

Usage

get_genotype_traits()

Value

A numeric data.frame with genotypes as row names and traits as columns.

Examples

geno <- get_genotype_traits()
head(geno)

Read a CA-ready numeric data table

Description

Reads a delimited text file into a numeric data.frame suitable for CA. The first column is used as row names, and every remaining column is coerced to numeric.

Usage

read_ca_data(file, sep = ",", header = TRUE, row.names = 1,
  check.names = FALSE)

Arguments

file

Path to a delimited text file (e.g. CSV).

sep

Field separator passed to read.table. Defaults to ",".

header

Logical; does the file have a header row? Defaults to TRUE.

row.names

Column to use as row names, passed to read.table. Defaults to 1 (the first column).

check.names

Logical; passed to read.table. Defaults to FALSE so that column names are kept exactly as written in the file.

Value

A numeric data.frame with row names taken from the input file.

Examples

file <- system.file("extdata", "genotype_traits.csv", package = "CAbiplot")
data <- read_ca_data(file)
head(data)

Run Correspondence Analysis on a numeric data table

Description

Thin, validating wrapper around CA. Accepts either a numeric matrix/data.frame already in memory, or a path to a delimited text file, which is read with read_ca_data.

Usage

run_ca(data, ...)

Arguments

data

A numeric matrix, numeric data.frame, or a path (character string) to a delimited text file to be read with read_ca_data.

...

Additional arguments passed on to CA (for example ncp, row.sup, col.sup).

Value

An object of class "CA" as returned by CA, computed with graph = FALSE.

Examples

geno <- get_genotype_traits()
res.ca <- run_ca(geno)
summary(res.ca)