Plot enrichment counts per group (and optional interaction)
Source:R/alpha_plots.R
plot_enrichment_counts.RdVisualizes per-sample peptide enrichment counts across groups in a
<phip_data> object, with optional interaction of multiple grouping
variables. Presence is defined by exist > 0. The plot(s) are produced by
an internal helper .plot_enrichment_counts_one().
Usage
plot_enrichment_counts(
phip_data,
group_cols = NULL,
prevalence_threshold = 0.05,
custom_colors = NULL,
binwidth = 1,
group_interaction = FALSE,
interaction_only = FALSE,
interaction_sep = " * ",
annotation_size = 4,
...
)Arguments
- phip_data
A
<phip_data>object withdata_longcontaining at leastsample_id,peptide_id, andexist.- group_cols
Character vector of grouping columns in
data_long, orNULLto plot all samples together.- prevalence_threshold
Numeric in
[0,1]; minimum prevalence used by.plot_enrichment_counts_one()to filter/annotate bins (default0.05).- custom_colors
Optional named vector for group colors passed through to
.plot_enrichment_counts_one()(defaultNULL).- binwidth
Numeric bin width for histograms (default
1).- group_interaction
Logical; also compute a plot for the interaction of all
group_cols(defaultFALSE).- interaction_only
Logical; if
TRUE, return only the interaction plot (requiresgroup_interaction = TRUEand at least twogroup_cols).- interaction_sep
Character separator for interaction labels (default
" * ").- annotation_size
Numeric; size of the in-plot threshold annotations (passed to
geom_text(size = ...)). Typical range 3–6. Default4.- ...
Reserved for future extensions; ignored.
Value
A single plot object (when
group_cols = NULL, or when only one plot is produced), orA named list of plot objects (when multiple plots are produced).
Details
If
group_cols = NULL, a single plot is returned for all samples.If
group_colsis a character vector, a list of plots is returned (one per grouping column) unlessinteraction_only = TRUE.If
group_interaction = TRUEand at least twogroup_colsare supplied, an additional interaction plot is created whose label joins groups usinginteraction_sep.If
interaction_only = TRUE, only the interaction plot is returned (this requiresgroup_interaction = TRUEand at least twogroup_cols).
Examples
# per-group plots
pd <- load_example_data()
p <- plot_enrichment_counts(pd, group_cols = c("group","timepoint"))
#> [18:40:45] INFO Plotting enrichment counts (<phip_data>)
#> -> group_cols: 'group', 'timepoint'
#> [18:40:45] INFO building enrichment count plot
#> -> grouping variable: 'group'
#> [18:40:45] OK plot built
#> [18:40:45] OK building enrichment count plot - done
#> -> elapsed: 0.266s
#> [18:40:45] INFO building enrichment count plot
#> -> grouping variable: 'timepoint'
#> [18:40:45] OK plot built
#> [18:40:45] OK building enrichment count plot - done
#> -> elapsed: 0.54s
#> [18:40:45] OK Plotting enrichment counts (<phip_data>) - done
#> -> elapsed: 0.808s
# add interaction plot
p2 <- plot_enrichment_counts(pd,
group_cols = c("group","timepoint"),
group_interaction = TRUE
)
#> [18:40:45] INFO Plotting enrichment counts (<phip_data>)
#> -> group_cols: 'group', 'timepoint'
#> [18:40:45] INFO building enrichment count plot
#> -> grouping variable: 'group'
#> [18:40:46] OK plot built
#> [18:40:46] OK building enrichment count plot - done
#> -> elapsed: 0.228s
#> [18:40:46] INFO building enrichment count plot
#> -> grouping variable: 'timepoint'
#> [18:40:46] OK plot built
#> [18:40:46] OK building enrichment count plot - done
#> -> elapsed: 0.232s
#> [18:40:46] INFO building enrichment count plot
#> -> grouping variable: '..phip_interaction..'
#> [18:40:46] OK plot built
#> [18:40:46] OK building enrichment count plot - done
#> -> elapsed: 0.227s
#> [18:40:46] OK Plotting enrichment counts (<phip_data>) - done
#> -> elapsed: 0.696s
# interaction only
p3 <- plot_enrichment_counts(pd,
group_cols = c("group","timepoint"),
group_interaction = TRUE,
interaction_only = TRUE
)
#> [18:40:46] INFO Plotting enrichment counts (<phip_data>)
#> -> group_cols: 'group', 'timepoint'
#> [18:40:46] INFO building enrichment count plot
#> -> grouping variable: '..phip_interaction..'
#> [18:40:46] OK plot built
#> [18:40:46] OK building enrichment count plot - done
#> -> elapsed: 0.24s
#> [18:40:46] OK Plotting enrichment counts (<phip_data>) - done
#> -> elapsed: 0.248s