Title: | Publication-Ready PCA, t-SNE, and UMAP Plots |
---|---|
Description: | Provides tools for creating publication-ready dimensionality reduction plots, including Principal Component Analysis (PCA), t-Distributed Stochastic Neighbor Embedding (t-SNE), and Uniform Manifold Approximation and Projection (UMAP). This package helps visualize high-dimensional data with options for custom labels, density plots, and faceting, using the 'ggplot2' framework Wickham (2016) <doi:10.1007/978-3-319-24277-4>. |
Authors: | Yaoxiang Li [cre, aut] |
Maintainer: | Yaoxiang Li <[email protected]> |
License: | GPL-3 |
Version: | 0.1.2 |
Built: | 2024-11-05 05:19:47 UTC |
Source: | https://github.com/yaoxiangli/ggpca |
This function generates dimensionality reduction plots (PCA, t-SNE, UMAP) with options for custom labels, titles, density plots, and faceting. It allows users to visualize high-dimensional data using various dimensionality reduction techniques.
ggpca( data, metadata_cols, mode = c("pca", "tsne", "umap"), scale = TRUE, x_pc = "PC1", y_pc = "PC2", color_var = "Species", ellipse = TRUE, ellipse_level = 0.9, ellipse_type = "norm", ellipse_alpha = 0.9, point_size = 3, point_alpha = 0.6, facet_var = NULL, tsne_perplexity = 30, umap_n_neighbors = 15, density_plot = "none", color_palette = "Set1", xlab = NULL, ylab = NULL, title = NULL, subtitle = NULL, caption = NULL )
ggpca( data, metadata_cols, mode = c("pca", "tsne", "umap"), scale = TRUE, x_pc = "PC1", y_pc = "PC2", color_var = "Species", ellipse = TRUE, ellipse_level = 0.9, ellipse_type = "norm", ellipse_alpha = 0.9, point_size = 3, point_alpha = 0.6, facet_var = NULL, tsne_perplexity = 30, umap_n_neighbors = 15, density_plot = "none", color_palette = "Set1", xlab = NULL, ylab = NULL, title = NULL, subtitle = NULL, caption = NULL )
data |
A data frame containing the data to be plotted. Must include both feature columns (numeric) and metadata columns (categorical). |
metadata_cols |
A character vector of column names or a numeric vector of column indices for the metadata columns. These columns are used for grouping and faceting. |
mode |
The dimensionality reduction method to use. One of |
scale |
Logical indicating whether to scale features (default: |
x_pc |
Name of the principal component or dimension to plot on the x-axis (default: |
y_pc |
Name of the principal component or dimension to plot on the y-axis (default: |
color_var |
Name of the column used to color points in the plot (default: |
ellipse |
Logical indicating whether to add confidence ellipses for groups (only supported for PCA; default: |
ellipse_level |
Confidence level for ellipses (default: |
ellipse_type |
Type of ellipse to plot, e.g., "norm" for normal distribution (default: |
ellipse_alpha |
Transparency level for ellipses, where 0 is fully transparent and 1 is fully opaque (default: |
point_size |
Size of the points in the plot (default: |
point_alpha |
Transparency level for the points, where 0 is fully transparent and 1 is fully opaque (default: |
facet_var |
Formula for faceting the plot (e.g., |
tsne_perplexity |
Perplexity parameter for t-SNE, which balances local and global aspects of the data (default: |
umap_n_neighbors |
Number of neighbors for UMAP, which determines the local structure (default: |
density_plot |
Controls whether to add density plots for the x, y, or both axes. Accepts one of |
color_palette |
Name of the color palette to use for the plot. Supports |
xlab |
Custom x-axis label (default: |
ylab |
Custom y-axis label (default: |
title |
Plot title (default: |
subtitle |
Plot subtitle (default: |
caption |
Plot caption (default: |
A ggplot2
object representing the dimensionality reduction plot, including scatter plots, optional density plots, and faceting options. The plot can be further customized using ggplot2
functions.
# Load dataset pca_data <- read.csv(system.file("extdata", "example.csv", package = "ggpca")) # PCA example p_pca_y_group <- ggpca( pca_data, metadata_cols = c(1:6), mode = "pca", color_var = "group", ellipse = TRUE, density_plot = "y", title = "PCA with Y-axis Density Plot", subtitle = "Example dataset, colored by group", caption = "Data source: Example dataset" ) print(p_pca_y_group) # t-SNE example p_tsne_time <- ggpca( pca_data, metadata_cols = c(1:6), mode = "tsne", color_var = "time", tsne_perplexity = 30, title = "t-SNE Plot of Example Dataset", subtitle = "Colored by time", caption = "Data source: Example dataset" ) print(p_tsne_time)
# Load dataset pca_data <- read.csv(system.file("extdata", "example.csv", package = "ggpca")) # PCA example p_pca_y_group <- ggpca( pca_data, metadata_cols = c(1:6), mode = "pca", color_var = "group", ellipse = TRUE, density_plot = "y", title = "PCA with Y-axis Density Plot", subtitle = "Example dataset, colored by group", caption = "Data source: Example dataset" ) print(p_pca_y_group) # t-SNE example p_tsne_time <- ggpca( pca_data, metadata_cols = c(1:6), mode = "tsne", color_var = "time", tsne_perplexity = 30, title = "t-SNE Plot of Example Dataset", subtitle = "Colored by time", caption = "Data source: Example dataset" ) print(p_tsne_time)
This function launches the Shiny application with the specified user interface and server function. The function does not return a value but starts the Shiny app, allowing users to interact with it.
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
run_app( onStart = NULL, options = list(), enableBookmarking = NULL, uiPattern = "/", ... )
onStart |
A function that will be called before the app is actually run.
This is only needed for |
options |
Named options that should be passed to the |
enableBookmarking |
Can be one of |
uiPattern |
A regular expression that will be applied to each |
... |
Arguments to pass to 'golem_opts'. See '?golem::get_golem_options' for more details. |
No return value, called for side effects.