PCA: Simple PCA

View source: R/utils-plot.R

PCAR Documentation

Simple PCA

Description

Perform a simple PCA using stats::prcomp. Optionally, it will create a PCA biplot using factoextra::fviz_pca_biplot if plot = TRUE.

Usage

PCA(data, plot = TRUE, ...)

Arguments

data

A numeric or complex matrix (or data frame) that will be used to perform the Principal Components Analysis.

plot

Boolean flag to indicate whether or not to create a PCA biplot.

...

Arguments passed on to factoextra::fviz_pca_biplot.

Value

Data frame with PCA result.

Examples


# Toy dataset
example_data <- data.frame(ID = c(1,2,3,4,5), 
                           P1 = c("one", "two", "three", "four", "five"), 
                           T1 = rnorm(5), 
                           T2 = rnorm(5))
example_data_pca <- PCA(example_data[, -c(1:2)])

# F1 Seedling Ionomics dataset
data(ionomics) # Includes some missing data
ionomics_rev <- MetaPipe::replace_missing(ionomics, 
                                          excluded_columns = c(1, 2),
                                          replace_na =  TRUE)
ionomics_pca <- PCA(ionomics_rev[, -c(1:2)])


villegar/MetaPipe documentation built on Nov. 22, 2022, 10:44 p.m.