plotContingency {benchdamic} | R Documentation

## plotContingency

### Description

Plot of the contingency tables for the chosen method. The top-left cells are colored, according to Fisher exact tests' p-values, if the number of features in those cells are enriched.

### Usage

    plotContingency(enrichment, method, levels_to_plot)

### Arguments

`enrichment` | enrichment object produced by createEnrichment function.
`method` | name of the method to plot.
`levels_to_plot` | A character vector containing the levels of the enrichment variable to plot.

### Value

a `ggplot2` object.

### See Also

`createEnrichment`, `plotEnrichment`, and `plotMutualFindings`.

### Examples

    data("ps_plaque_16S")
    data("microbial_metabolism")

    # Extract genera from the phyloseq tax_table slot
    genera <- phyloseq::tax_table(ps_plaque_16S)[, "GENUS"]
    # Genera as rownames of microbial_metabolism data.frame
    rownames(microbial_metabolism) <- microbial_metabolism$Genus
    # Match OTUs to their metabolism
    priorInfo <- data.frame(genera,
        "Type" = microbial_metabolism[genera, "Type"]
    )
    # Unmatched genera becomes "Unknown"
    unknown_metabolism <- is.na(priorInfo$Type)
    priorInfo[unknown_metabolism, "Type"] <- "Unknown"
    priorInfo$Type <- factor(priorInfo$Type)
    # Add a more informative names column
    priorInfo[, "newNames"] <- paste0(rownames(priorInfo), priorInfo[, "GENUS"])

    # DA analysis
    # Add scaling factors
    ps_plaque_16S <- norm_edgeR(object = ps_plaque_16S, method = "TMM")
    ps_plaque_16S <- norm_CSS(object = ps_plaque_16S, method = "median")

    # Perform DA analysis
    Plaque_16S_DA <- list()
    Plaque_16S_DA <- within(Plaque_16S_DA, {
        # DA analysis
        da.limma <- DA_limma(
            object = ps_plaque_16S,
            design = ~ 1 + HMP_BODY_SUBSITE,
            coef = 2,
            norm = "TMM"
        )
        da.limma.css <- DA_limma(
            object = ps_plaque_16S,
            design = ~ 1 + HMP_BODY_SUBSITE,
            coef = 2,
            norm = "CSSmedian"
        )
    })

    enrichment <- createEnrichment(
        object = Plaque_16S_DA,
        priorKnowledge = priorInfo, enrichmentCol = "Type", namesCol = "GENUS",
        slot = "pValMat", colName = "adjP", type = "pvalue", direction = "logFC",
        threshold_pvalue = 0.1, threshold_logfc = 1, top = 10, verbose = TRUE
    )
    # Contingency tables
    plotContingency(enrichment = enrichment, method = "limma.TMM")
    # Barplots
    plotEnrichment(enrichment, enrichmentCol = "Type")
    # Mutual findings
    plotMutualFindings(
        enrichment = enrichment, enrichmentCol = "Type",
        n_methods = 1
    )

[Package benchdamic version 1.0.0 Index]