View source: R/visualize_gsea.R
visualize_gsea | R Documentation |
This function creates various visualizations for Gene Set Enrichment Analysis (GSEA) results. It automatically detects whether pathway names are available (from gsea_pathway_annotation()) and uses them for better readability, falling back to pathway IDs if names are not available.
visualize_gsea(
gsea_results,
plot_type = "enrichment_plot",
n_pathways = 20,
sort_by = "p.adjust",
colors = NULL,
abundance = NULL,
metadata = NULL,
group = NULL,
network_params = list(),
heatmap_params = list(),
pathway_label_column = NULL
)
gsea_results |
A data frame containing GSEA results from the pathway_gsea function |
plot_type |
A character string specifying the visualization type: "enrichment_plot", "dotplot", "barplot", "network", or "heatmap" |
n_pathways |
An integer specifying the number of pathways to display |
sort_by |
A character string specifying the sorting criterion: "NES", "pvalue", or "p.adjust" |
colors |
A vector of colors for the visualization |
abundance |
A data frame containing the original abundance data (required for heatmap visualization) |
metadata |
A data frame containing sample metadata (required for heatmap visualization) |
group |
A character string specifying the column name in metadata that contains the grouping variable (required for heatmap visualization) |
network_params |
A list of parameters for network visualization |
heatmap_params |
A list of parameters for heatmap visualization |
pathway_label_column |
A character string specifying which column to use for pathway labels. If NULL (default), the function will automatically use 'pathway_name' if available, otherwise 'pathway_id'. This allows for custom labeling when using annotated GSEA results. |
A ggplot2 object or ComplexHeatmap object
## Not run:
# Load example data
data(ko_abundance)
data(metadata)
# Prepare abundance data
abundance_data <- as.data.frame(ko_abundance)
rownames(abundance_data) <- abundance_data[, "#NAME"]
abundance_data <- abundance_data[, -1]
# Run GSEA analysis
gsea_results <- pathway_gsea(
abundance = abundance_data,
metadata = metadata,
group = "Environment",
pathway_type = "KEGG",
method = "fgsea"
)
# Create enrichment plot with pathway IDs (default)
visualize_gsea(gsea_results, plot_type = "enrichment_plot", n_pathways = 10)
# Annotate results for better pathway names
annotated_results <- gsea_pathway_annotation(
gsea_results = gsea_results,
pathway_type = "KEGG"
)
# Create plots with readable pathway names
visualize_gsea(annotated_results, plot_type = "dotplot", n_pathways = 20)
visualize_gsea(annotated_results, plot_type = "barplot", n_pathways = 15)
# Create network plot with custom labels
visualize_gsea(annotated_results, plot_type = "network", n_pathways = 15)
# Use custom column for labels (if available)
visualize_gsea(annotated_results, plot_type = "barplot",
pathway_label_column = "pathway_name", n_pathways = 10)
# Create heatmap
visualize_gsea(
annotated_results,
plot_type = "heatmap",
n_pathways = 15,
abundance = abundance_data,
metadata = metadata,
group = "Environment"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.