plotEnrichR: Visualise Enrichr results as barplots

View source: R/func_markers.R

plotEnrichRR Documentation

Visualise Enrichr results as barplots

Description

This function takes a list of list of DataFrames containing Enrichr results returned by runEnrichR() and create barplots from a selected gene-set library.

Usage

plotEnrichR(
  object,
  db,
  showTerms = 20,
  numChar = 50,
  y = "Count",
  order_by = "P.value",
  theme_size = 16,
  prefix = NULL,
  dir_path = NULL,
  ...
)

Arguments

object

A named list of list of DataFrames storing outputs returned by runEnrichR(), each of which contains results for the corresponding group of comparison.

db

A string indicating the name of one gene-set library to plot.

showTerms

An integer scalar indicating the number of terms to show. Default is 20.

numChar

An integer scalar indicating the number characters to keep in the terms' descriptions. Default is 50.

y

A string indicating the variable that should be mapped to the y-axis. It can be "Count" and "Ratio". Default is "Count".

order_by

A string indicating how to order the Enrichr terms before selecting the first showTerms terms to plot. It can be "P.value" or "Combined.Score". Default is "P.value".

theme_size

A numeric scalar indicating the base font size. Default is 16.

prefix

A string indicating the prefix of output file. When prefix = NULL, the plots are shown in the current graphics device using grid::grid.draw(). The plots are saved to PDF files using ggsave() when prefix is not NULL. Default is NULL.

dir_path

The directory path for exported PDF. The files are exported to the current working directory when file_path = NULL. Default is NULL.

...

Other arguments passed on to ggsave().

Details

The function prints barplots from each group of comparison using grid::grid.draw() one after another, therefore the plotting feature is suitable only in Jupyter Notebook or R Markdown. Otherwise, disable plotting by specifying the prefix argument to save barplots to PDF files.

Value

None

Author(s)

I-Hsuan Lin

See Also

runEnrichR(), ggplot2::ggsave()

Examples

## Not run: 
# Load demo dataset
data(res_deseq2)

# We construct a list of 3 DataFrames using the same DESeq2 output (`res_deseq2`)
# to mimic having a list containing results from multiple sets of comparisons.
res.de <- list(A_B = res_deseq2, A_C = res_deseq2, B_C = res_deseq2)

# Select gene-set libraries
dbs <- c("GO_Molecular_Function_2018", "GO_Biological_Process_2018")

# Run enrichR using the D. melanogaster specific modEnrichr site, and
# specify the gene symbols are stored in the 'external_gene_name' column
res.ora <- runEnrichR(res.de,
  dbs = dbs, site = "FlyEnrichr",
  column_by = "external_gene_name"
)

# Print plots on to standard output
plotEnrichR(res.ora, db = "GO_Biological_Process_2018", theme_size = 14)

# Save plots to PDF files in the per-session temporary directory
plotEnrichR(res.ora,
  db = "GO_Biological_Process_2018", prefix = "Enrichr",
  dir_path = tempdir(), width = 12, height = 5
)

## End(Not run)

ycl6/scRUtils documentation built on Feb. 18, 2025, 6:14 a.m.