FactoJulia is a Julia package for performing Principal Component Analysis (PCA) with visualization, inspired by FactoMineR in R. It provides clear outputs for eigenvalues, loadings, variable contributions, and automatically generates and saves PCA plots.
- Compute PCA on numeric datasets
- Center and scale variables
- Print PCA results like FactoMineR (coordinates, cos2, contributions)
- Generate high-quality plots:
- Scree plot
- Individuals factor map
- Variables correlation circle
- Save plots automatically for future reference
using Pkg
Pkg.add("https://github.com/Adrien-Sli/Factojulia.jl.git")Or, for development:
Pkg.clone("https://github.com/Adrien-Sli/FactoJulia.jl.git")
Pkg.activate("FactoJulia.jl")using FactoJulia
using CSV, DataFrames
# Load a dataset
df = CSV.read("PATH TO YOUR DATA.csv", DataFrame)
# Or if you wish to quickly check correct installation, uncomment the line below and remove the previous one
# df = CSV.read("test/test_data.csv", DataFrame)
# Perform PCA
result = PCA_(df; scale=true, ncp=5, graph=true)
# Access PCA outputs
scores = result.scores # Principal component scores
loadings = result.loadings # Loadings (eigenvectors)
eigvals = result.eigvals # Eigenvalues
propvar = result.propvar # Variance explained (%)
cumvar = result.cumvar # Cumulative variance explained- Scree plot – shows variance explained by each component
- Individuals factor map – visualizes samples in PCA space with 4 quadrants
- Variables factor map – correlation circle with variable arrows
All plots are automatically displayed and saved in the src/test/plots folder.
You can control which components to display in factor maps:
plot_PCA_individuals(result.scores; pcs=(1,3))
plot_PCA_variables(result.loadings; pcs=(1,3), var_names=result.colnames)FactoJulia.jl/
├─ src/
│ ├─ pca.jl # Main PCA functions
│ ├─ FactoJulia.jl # Module entrypoint
│ └─ test/
│ └─ plots/ # Automatically saved plots
├─ test/ # Unit tests
├─ Project.toml
└─ README.md
If you use FactoJulia.jl in your work, please mention it in your publication, project, or report. A simple citation like the following is appreciated:
PCA analysis was performed using the FactoJulia.jl package by Stave Icnel Dany OSIAS, Adrien SLIFIRSKI, Keevson Judlin VAL, Miller ABESSOLO, Hanaa HAJMI.