Visualize principal component analysis (PCA) results stored within a
GenEDA object. This function extracts PCA data via ExtractPCA
and provides a flexible ggplot2-based visualization interface.
Usage
PlotPCA(
object,
x = 1,
y = 2,
color_by,
colors = NULL,
split_by = NULL,
shape_by = NULL,
return_data = FALSE
)Arguments
- object
A
GenEDAobject containing PCA results in theDimReductionslot.- x
Numeric or character. The principal component to plot on the x-axis (e.g., 1 or "PC1").
- y
Numeric or character. The principal component to plot on the y-axis (e.g., 2 or "PC2").
- color_by
Character. Column name in the metadata used to color points.
- colors
Vector. Custom colors to use for plotting
- split_by
Character (optional). Column name in metadata used for faceting (creates separate panels).
- shape_by
Character (optional). Column name in metadata used to control point shape.
- return_data
Logical (default = FALSE), whether or not to return pca dataframe for more custom plotting.
Value
A ggplot object displaying the PCA scatter plot, or a list of
pca_df and plot if return_data = TRUE
Examples
data(Snail1KO)
counts <- as.matrix(Snail1KO$rawCounts)
counts <- counts[rowSums(counts >= 10) >= 3, ]
meta <- Snail1KO$metadata
rownames(meta) <- meta$Sample
norm <- log2(t(t(counts) / colSums(counts)) * 1e6 + 1)
obj <- GenEDA(normalized = norm, metadata = meta, counts = counts)
obj <- FindVariableFeatures(obj, nfeatures = 1000)
obj <- RunPCA(obj)
#> Calculating principal components from top 1000 HVGs
#> Percent variations:
#> PC1: 88.56 %
#> PC2: 5.9 %
#> PC3: 2.91 %
#> PC4: 1.55 %
#> PC5: 1.08 %
#> PC6: 0 %
PlotPCA(obj,
x = 1, y = 2, color_by = "Genotype",
colors = c(WT = "grey40", Snai1_KO = "firebrick3")
)
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> ℹ Please use tidy evaluation idioms with `aes()`.
#> ℹ See also `vignette("ggplot2-in-packages")` for more information.
#> ℹ The deprecated feature was likely used in the RGenEDA package.
#> Please report the issue at
#> <https://github.com/mikemartinez99/RGenEDA/issues>.
