pub struct BracketTable {
pub label: Option<String>,
pub group1: String,
pub group2: String,
pub p_column: Option<String>,
pub y_position: String,
pub step_increase: f64,
pub hide_ns: bool,
pub cutpoints: Vec<(f64, String)>,
pub geom: GeomBracketStyle,
}Expand description
Significance brackets from a precomputed test table — ggpubr’s
stat_pvalue_manual() / geom_bracket(data = test_table). Nothing is
recomputed: every bracket comes from one table row.
The defaults read the anofox test contract schema (group1, group2,
p_adj, p_value, test_id, …) and the ggpubr/rstatix columns
y_position / label:
- groups:
group1/group2name the x categories the bracket spans. Rows with a missing group, or a group that is not a level of the plot’s x column, are dropped with a warning. - p-value: per row,
p_adjwhen present and notNULL, elsep_value(override withp_column). - label: the
labeltemplate if set; otherwise a non-nulllabelcolumn; otherwise"p = {p}". - height: a finite
y_positionis used as-is; rows without one are stacked automatically above the data (and above any given positions),step_increase× the data’s y range apart.
Label templates substitute {column} with that row’s value. Special keys:
{p} (the chosen p-value), {p.signif} / {stars} (significance stars by
cutpoints) and {p.format} ("p = 0.0123"-style).
Numeric columns whose name starts with p are printed like p-values
(4 significant digits, scientific below 1e-4); other values as in
tooltips. Unknown keys are left verbatim; NULL prints as NA.
use ggplot_rs::prelude::*;
use ggplot_rs::data::Value;
let tests = vec![
("group1".to_string(), vec![Value::Str("a".into()), Value::Str("a".into())]),
("group2".to_string(), vec![Value::Str("b".into()), Value::Str("c".into())]),
("p_adj".to_string(), vec![Value::Float(0.003), Value::Float(0.2)]),
];
let data = vec![
("g".to_string(), ["a", "b", "c"].iter().map(|s| Value::Str(s.to_string())).collect()),
("y".to_string(), vec![Value::Float(1.0), Value::Float(2.0), Value::Float(3.0)]),
];
let svg = GGPlot::new(data)
.aes(Aes::new().x("g").y("y"))
.geom_point()
.geom_bracket_table(tests, BracketTable::new().label("p = {p_adj} {stars}"))
.render_svg_native()
.unwrap();
assert!(svg.contains("p = 0.003 **"));Fields§
§label: Option<String>Label template (see the type docs); None = label column or "p = {p}".
group1: StringColumn naming the left group.
group2: StringColumn naming the right group.
p_column: Option<String>Explicit p-value column; None = p_adj, falling back to p_value.
y_position: StringColumn with explicit bracket heights.
step_increase: f64Gap between auto-stacked brackets as a fraction of the data’s y range.
hide_ns: boolDrop non-significant rows (p above the last-but-one cutpoint, i.e.
labelled ns).
cutpoints: Vec<(f64, String)>Significance-star cutpoints (upper bound, symbol), ascending; a p
at or below a bound gets that symbol. Default (ggpubr):
≤1e-4 ****, ≤0.001 ***, ≤0.01 **, ≤0.05 *, else ns.
geom: GeomBracketStyleBracket appearance.
Implementations§
Source§impl BracketTable
impl BracketTable
pub fn new() -> Self
Sourcepub fn p_column(self, col: &str) -> Self
pub fn p_column(self, col: &str) -> Self
Read the p-value from this column instead of p_adj/p_value.
Sourcepub fn groups(self, group1: &str, group2: &str) -> Self
pub fn groups(self, group1: &str, group2: &str) -> Self
Use other column names for the compared groups.
Sourcepub fn y_position(self, col: &str) -> Self
pub fn y_position(self, col: &str) -> Self
Read explicit heights from this column (default y_position).
Sourcepub fn step_increase(self, step: f64) -> Self
pub fn step_increase(self, step: f64) -> Self
Spacing of auto-stacked brackets (fraction of the y range; default 0.12).
Sourcepub fn cutpoints(self, cutpoints: &[(f64, &str)]) -> Self
pub fn cutpoints(self, cutpoints: &[(f64, &str)]) -> Self
Custom significance-star cutpoints (upper bound, symbol), ascending.
Sourcepub fn style(self, style: GeomBracketStyle) -> Self
pub fn style(self, style: GeomBracketStyle) -> Self
Bracket appearance.
Trait Implementations§
Source§impl Clone for BracketTable
impl Clone for BracketTable
Auto Trait Implementations§
impl Freeze for BracketTable
impl RefUnwindSafe for BracketTable
impl Send for BracketTable
impl Sync for BracketTable
impl Unpin for BracketTable
impl UnsafeUnpin for BracketTable
impl UnwindSafe for BracketTable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more