The plot module provides five publication-ready plotting functions:
| Function | Purpose |
|---|---|
plot_bar() |
Bar chart with optional grouping and sorting |
plot_density() |
Density / distribution curves with optional faceting |
plot_pie() |
Pie / donut chart from a vector or data frame |
plot_venn() |
Venn diagram for 2–4 sets |
plot_forest() |
Publication-ready forest plot |
Note: All code examples in this vignette are static (
eval = FALSE). Output is hand-written to reflect the current implementation.
plot_bar() — Bar chart with optional groupingCreates a vertical or horizontal bar chart. Bars can be sorted, and
an optional group_col produces a grouped (side-by-side)
chart. All inputs are character column names, so the function works
naturally in pipelines.
Key parameters
| Parameter | Default | Description |
|---|---|---|
data |
— | Data frame |
x_col |
— | Column for x-axis categories |
y_col |
— | Column for bar heights |
horizontal |
FALSE |
Flip to a horizontal bar chart |
sort |
FALSE |
Sort bars by height |
decreasing |
TRUE |
Sort order when sort = TRUE |
group_col |
NULL |
Column for grouped bars |
sort_by |
"union" |
Which groups to base sort order on |
plot_density() — Distribution curvesDraws kernel density curves via geom_density. Supports
multi-group overlays, optional faceting, and palette customisation.
Key parameters
| Parameter | Default | Description |
|---|---|---|
data |
— | Data frame |
x_col |
— | Numeric column for the distribution |
group_col |
NULL |
Column for overlaid group curves |
facet_col |
NULL |
Column for faceted panels |
alpha |
0.3 |
Fill transparency |
adjust |
1 |
Bandwidth multiplier |
palette |
NULL |
Named or unnamed character vector of colours |
df3 <- data.frame(
score = c(rnorm(150, 50, 10), rnorm(150, 60, 12)),
group = rep(c("A", "B"), each = 150),
cohort = rep(c("Discovery", "Replication"), 150)
)
plot_density(df3, x_col = "score", group_col = "group", facet_col = "cohort")
#> # Two facet panels (Discovery / Replication), each with two group curvesplot_pie() — Pie / donut chartAccepts either a plain named vector of counts or a data frame with separate group and count columns. Labels can show counts, percentages, both, or none.
Key parameters
| Parameter | Default | Description |
|---|---|---|
data |
— | Named numeric vector or data frame |
group_col |
NULL |
Column for slice labels (data frame only) |
count_col |
NULL |
Column for slice sizes (data frame only) |
label |
"percent" |
"count", "percent", "both",
or "none" |
palette |
NULL |
Character vector of fill colours |
plot_venn() — Venn diagram for 2–4 setsDraws classic (ggvenn) or gradient-filled
(ggVennDiagram) Venn diagrams. Both packages are in
Suggests — install the one you need.
Key parameters
| Parameter | Default | Description |
|---|---|---|
set1, set2 |
— | Required input vectors |
set3, set4 |
NULL |
Optional third and fourth sets |
set_names |
NULL |
Override labels (default: variable names) |
method |
"classic" |
"classic" (ggvenn) or "gradient"
(ggVennDiagram) |
label |
"count" |
"count", "percent", "both",
or "none" |
palette |
NULL |
Fill colours (vector for classic; palette name for gradient) |
return_sets |
FALSE |
Return list(plot, sets) instead of just the plot |
plot_forest() — Publication-ready forest plotProduces a publication-ready forest plot with automatic OR (95% CI)
label generation, p-value formatting, row bolding, background shading,
and three-line borders. Built on forestploter.
Key parameters
| Parameter | Default | Description |
|---|---|---|
data |
— | Data frame; first column is the row label |
est |
— | Numeric vector of point estimates (NA = header
row) |
lower, upper |
— | CI lower and upper bounds |
ci_column |
2L |
Column position for the CI graphic |
ref_line |
1 |
Reference line (use 0 for beta coefficients) |
xlim |
c(0, 2) |
X-axis limits |
p_cols |
NULL |
Numeric column(s) to auto-format as p-values |
indent |
NULL |
Per-row indentation level (0 = parent, 1+ = sub-row) |
bold_label |
NULL |
Logical vector for label bolding |
background |
"zebra" |
"zebra", "bold_label", or
"none" |
save |
FALSE |
Save output to file |
dest |
NULL |
File path when save = TRUE |
df <- data.frame(
item = c("Exposure vs. control", "Unadjusted", "Fully adjusted"),
`Cases/N` = c("", "89/4521", "89/4521"),
p_value = c(NA_real_, 0.001, 0.006),
check.names = FALSE
)
p <- plot_forest(
data = df,
est = c(NA, 1.52, 1.43),
lower = c(NA, 1.18, 1.11),
upper = c(NA, 1.96, 1.85),
ci_column = 2L,
indent = c(0L, 1L, 1L),
p_cols = "p_value",
xlim = c(0.5, 3.0)
)
plot(p)
#> # Forest plot — header row bolded, two indented model rows,
#> # OR (95% CI) column auto-generated, significant p-values boldeddf2 <- data.frame(
item = c("Biomarker A", " Model 1", " Model 2",
"Biomarker B", " Model 1", " Model 2"),
N = c("", "4521", "4521", "", "4389", "4389"),
p_value = c(NA, 0.001, 0.012, NA, 0.034, 0.21),
check.names = FALSE
)
p2 <- plot_forest(
data = df2,
est = c(NA, 1.52, 1.43, NA, 0.88, 0.91),
lower = c(NA, 1.18, 1.11, NA, 0.72, 0.74),
upper = c(NA, 1.96, 1.85, NA, 1.07, 1.12),
ci_column = 2L,
indent = c(0L, 1L, 1L, 0L, 1L, 1L),
bold_label = c(TRUE, FALSE, FALSE, TRUE, FALSE, FALSE),
p_cols = "p_value",
xlim = c(0.5, 2.5),
background = "bold_label"
)
plot(p2)
#> # Two parent rows (bolded, shaded) with four indented sub-rowsp3 <- plot_forest(
data = df,
est = c(NA, 1.52, 1.43),
lower = c(NA, 1.18, 1.11),
upper = c(NA, 1.96, 1.85),
ci_column = 2L,
indent = c(0L, 1L, 1L),
ci_col = c(NA, "#E74C3C", "#3498DB"),
p_cols = "p_value",
xlim = c(0.5, 3.0)
)
plot(p3)
#> # Red CI for Unadjusted model, blue CI for Fully adjusted modelplot_forest(
data = df,
est = c(NA, 1.52, 1.43),
lower = c(NA, 1.18, 1.11),
upper = c(NA, 1.96, 1.85),
ci_column = 2L,
indent = c(0L, 1L, 1L),
p_cols = "p_value",
xlim = c(0.5, 3.0),
save = TRUE,
dest = "results/forest_plot",
save_width = 20,
save_height = 8
)
#> # Saves forest_plot.pdf, .png, .svg, .tiff to results/A typical analysis might use several plot functions together:
library(evanverse)
# Group sizes as a sorted bar chart
summary_df <- data.frame(
group = c("T_cell", "B_cell", "NK_cell", "Monocyte"),
n = c(423, 187, 95, 312)
)
plot_bar(summary_df, x_col = "group", y_col = "n",
sort = TRUE, horizontal = TRUE)
#> # Horizontal sorted bar chart
# Proportional composition as a pie chart
plot_pie(summary_df, group_col = "group", count_col = "n", label = "percent")
#> # Pie chart with percentage labels
# Score distributions per cell type
score_df <- data.frame(
score = c(rnorm(423, 55, 10), rnorm(187, 62, 9),
rnorm(95, 70, 8), rnorm(312, 48, 12)),
group = rep(c("T_cell", "B_cell", "NK_cell", "Monocyte"),
c(423, 187, 95, 312))
)
plot_density(score_df, x_col = "score", group_col = "group")
#> # Overlaid density curves for all four cell types
# DEG overlaps across comparisons
deg_tc <- paste0("GENE", sample(1:500, 80))
deg_bc <- paste0("GENE", sample(1:500, 65))
deg_nk <- paste0("GENE", sample(1:500, 45))
plot_venn(deg_tc, deg_bc, deg_nk,
set_names = c("T_cell DEGs", "B_cell DEGs", "NK_cell DEGs"))
#> # Three-set Venn of differentially expressed genes