Perform a simple PCA using stats::prcomp
.
Optionally, it will create a PCA biplot using
factoextra::fviz_pca_biplot
if
plot = TRUE
.
PCA(data, name = "PCA", plot = TRUE, width = 6, height = 6, ...)
A numeric or complex matrix (or data frame) that will be used to perform the Principal Components Analysis.
Output name with or without path.
Boolean flag to indicate whether or not to create a PCA biplot.
Width in inches.
Height in inches.
Arguments passed on to
factoextra::fviz_pca_biplot
.
Data frame with PCA result.
# \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)
# }