Plot P-value Distribution Colored by a Binned Fill Variable
Source:R/plot_pvalue_distribution.R
plot_pvalue_distribution.Rd
Visualizes the distribution of a variable (typically p-values) using a stacked histogram. Bars are colored based on binned values of a second variable (e.g., a test statistic), centered around zero. Out-of-range values are grouped into outermost bins labeled with `<=` and `>=`. The plot can be optionally faceted by a categorical column.
Usage
plot_pvalue_distribution(
data,
x_var,
fill_var = NULL,
facet_col = NULL,
facet_levels = NULL,
title = NULL,
x_label = NULL,
y_label = NULL,
fill_label = NULL,
bins = 50,
fill_bins = 9
)
Arguments
- data
A data frame containing at least the columns specified in
x_var
andfill_var
.- x_var
String. Name of the column to use for the x-axis (e.g., "p_value").
- fill_var
String. Name of the column used for fill coloring (e.g., "T_obs").
- facet_col
Optional. String. Name of a column to use for faceting the plot (e.g., "feature", "cluster"). If NULL, no faceting is applied.
- facet_levels
Optional. A character vector of levels to include in faceting. If NULL and
facet_col
is provided, the first 9 unique values are used.- title
Optional. Character string to set the plot title.
- x_label
Label for the x-axis. Defaults to the value of
x_var
.- y_label
Label for the y-axis. Defaults to
"Count"
.- bins
Integer. Number of bins to use for the x-axis histogram (default is 50).
- fill_bins
Integer. Number of bins to use for binning the fill variable (must be odd; default is 9). Bins are centered at 0 and symmetric. The outermost bins are labeled with
<=
and>=
.
Value
A ggplot2
object showing a histogram of x_var
, with bars stacked and colored by binned values of fill_var
. Faceting is applied if specified.
Examples
# Basic histogram
plot_pvalue_distribution(data = agg_perm, x_var = "p_value", fill_var = "T_obs")
#> Error: object 'agg_perm' not found
# Faceted by cluster
plot_pvalue_distribution(
data = agg_perm,
x_var = "p_value",
fill_var = "T_obs",
facet_col = "cluster"
)
#> Error: object 'agg_perm' not found