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, name = "PCA", plot = TRUE, width = 6, height = 6, ...)

Arguments

data

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

name

Output name with or without path.

plot

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

width

Width in inches.

height

Height in inches.

...

Arguments passed on to factoextra::fviz_pca_biplot.

Value

Data frame with PCA result.

Examples

# \donttest{
out_prefix <- file.path(tempdir(), "metapipe_PCA")
# 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 <- MetaPipe::PCA(example_data[, -c(1:2)],
                                  name = out_prefix)

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