Skip to main content

BracketTable

Struct BracketTable 

Source
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 / group2 name 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_adj when present and not NULL, else p_value (override with p_column).
  • label: the label template if set; otherwise a non-null label column; otherwise "p = {p}".
  • height: a finite y_position is 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: String

Column naming the left group.

§group2: String

Column naming the right group.

§p_column: Option<String>

Explicit p-value column; None = p_adj, falling back to p_value.

§y_position: String

Column with explicit bracket heights.

§step_increase: f64

Gap between auto-stacked brackets as a fraction of the data’s y range.

§hide_ns: bool

Drop 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: GeomBracketStyle

Bracket appearance.

Implementations§

Source§

impl BracketTable

Source

pub fn new() -> Self

Source

pub fn label(self, template: &str) -> Self

Label template, e.g. "p = {p_adj}" or "{p.signif}".

Source

pub fn stars(self) -> Self

Label each bracket with significance stars only ("{p.signif}").

Source

pub fn p_column(self, col: &str) -> Self

Read the p-value from this column instead of p_adj/p_value.

Source

pub fn groups(self, group1: &str, group2: &str) -> Self

Use other column names for the compared groups.

Source

pub fn y_position(self, col: &str) -> Self

Read explicit heights from this column (default y_position).

Source

pub fn step_increase(self, step: f64) -> Self

Spacing of auto-stacked brackets (fraction of the y range; default 0.12).

Source

pub fn hide_ns(self, hide: bool) -> Self

Hide non-significant comparisons.

Source

pub fn cutpoints(self, cutpoints: &[(f64, &str)]) -> Self

Custom significance-star cutpoints (upper bound, symbol), ascending.

Source

pub fn style(self, style: GeomBracketStyle) -> Self

Bracket appearance.

Source

pub fn signif(&self, p: f64) -> String

The star symbol for p (empty for a missing / non-finite p).

Trait Implementations§

Source§

impl Clone for BracketTable

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for BracketTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V