Skip to contents

Visualizes the output of enrichment_CTD. The function auto-detects the enrichment method from the input class and column structure:

  • ORA / GSEA (data frame with Count or NES): bar or dot plot of fold enrichment.

  • CAMERA (data frame with Direction and NGenes): bar or dot plot of \(-\log_{10}(\mathrm{padj})\), colored by direction of enrichment.

  • GSVA (numeric matrix chemicals x samples): heatmap of per-sample enrichment scores for the top-N chemicals selected by score variance across samples.

Usage

plot_CTD(results, type = "bar", n = 20, title = NULL)

Arguments

results

A data frame or numeric matrix returned by enrichment_CTD.

type

Character. Plot type for tabular results: "bar" (default) or "dot". Ignored for GSVA matrix input.

n

Integer. Number of top chemicals to display (default 20). Selection criterion: ascending padj for tabular results, descending score variance across samples for GSVA matrices.

title

Character. Plot title. If NULL (default), a title is generated automatically based on the detected method.

Value

A ggplot2 object.

Examples

sample_file <- system.file(
    "extdata", "CTD_chem_gene_ixns_sample.csv",
    package = "ctdR"
)
import_CTD(sample_file)
#> Reading CTD chemical-gene interactions from: /home/runner/work/_temp/Library/ctdR/extdata/CTD_chem_gene_ixns_sample.csv
#> Filtered to 86 human interactions
#> Mapping genes for 10 chemicals...
#> Warning: 10 ChemicalID(s) appear with more than one ChemicalName in the CTD file; only the first name per ID is retained. Affected IDs: D000082, D001564, D002104, D003907, D004958 ... (and 5 more)
#> CTD data cached successfully in: ~/.cache/ctdR
#>   10 chemicals | 17 unique genes | 0 s

# ORA / GSEA
genes <- data.frame(
    EntrezID = c("7124", "3569", "7157", "672", "1956"),
    pvalue = c(0.001, 0.003, 0.01, 0.02, 0.05)
)
ora_results <- enrichment_CTD(genes, method = "ORA")
#> Warning: column name ‘FoldEnrichment’ is duplicated in the result
plot_CTD(ora_results, type = "bar")

plot_CTD(ora_results, type = "dot")