Skip to main content

SurvivalPlot

Struct SurvivalPlot 

Source
pub struct SurvivalPlot {
    pub groups: Vec<KMGroup>,
    pub color: String,
    pub group_colors: Option<Vec<String>>,
    pub line_width: f64,
    pub show_ci: bool,
    pub ci_alpha: f64,
    pub show_censoring: bool,
    pub censoring_size: f64,
    pub pvalue_text: Option<String>,
    pub legend_label: Option<String>,
}
Expand description

Builder for a Kaplan-Meier survival plot.

Each group produces a step-function survival curve, optional confidence bands (Greenwood’s formula, linear scale), and optional censoring tick marks. When multiple groups are present a log-rank p-value can be annotated via with_pvalue_text.

§Example

use kuva::prelude::*;

let plot = SurvivalPlot::new()
    .with_group("Treatment A", vec![5.0,8.0,12.0,15.0,20.0], vec![true,true,false,true,false])
    .with_group("Treatment B", vec![3.0,6.0,9.0,14.0,18.0], vec![true,false,true,true,false])
    .with_ci(true)
    .with_legend("Group");

let plots = vec![Plot::from(plot)];
let layout = Layout::auto_from_plots(&plots)
    .with_title("Overall Survival")
    .with_x_label("Time (months)")
    .with_y_label("Survival probability");

Fields§

§groups: Vec<KMGroup>§color: String

Fallback line color when no per-group colors are set and no palette is active.

§group_colors: Option<Vec<String>>

Per-group color overrides (indexed by group order).

§line_width: f64

Line stroke width in pixels. Default 2.0.

§show_ci: bool

Draw Greenwood 95% CI bands. Default false.

§ci_alpha: f64

Opacity of CI bands. Default 0.2.

§show_censoring: bool

Draw censoring tick marks on the curves. Default true.

§censoring_size: f64

Half-height of censoring ticks in pixels. Default 4.0.

§pvalue_text: Option<String>

Optional p-value / annotation text rendered in the upper-right of the plot area.

§legend_label: Option<String>

Implementations§

Source§

impl SurvivalPlot

Source

pub fn new() -> Self

Create a survival plot with default settings.

Source

pub fn with_group( self, label: impl Into<String>, times: Vec<f64>, events: Vec<bool>, ) -> Self

Add a group with separate time and event vectors.

times: time to event or censoring. events: true = event occurred.

Source

pub fn with_colored_group( self, label: impl Into<String>, times: Vec<f64>, events: Vec<bool>, color: impl Into<String>, ) -> Self

Add a group with a per-group color override.

Source

pub fn with_color(self, color: impl Into<String>) -> Self

Set the fallback line color. Default "steelblue".

Source

pub fn with_group_colors( self, colors: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set per-group colors (indexed by group order). Falls back to category10.

Source

pub fn with_line_width(self, w: f64) -> Self

Set line stroke width in pixels. Default 2.0.

Source

pub fn with_ci(self, show: bool) -> Self

Show 95% confidence bands (Greenwood’s formula). Default false.

Source

pub fn with_ci_alpha(self, alpha: f64) -> Self

Set confidence band opacity. Default 0.2.

Source

pub fn with_censoring(self, show: bool) -> Self

Show censoring tick marks on curves. Default true.

Source

pub fn with_censoring_size(self, size: f64) -> Self

Set the half-height of censoring tick marks in pixels. Default 4.0.

Source

pub fn with_pvalue_text(self, text: impl Into<String>) -> Self

Add a p-value or annotation string rendered in the upper-right corner.

Typical use: with_pvalue_text("p = 0.023") or "log-rank p < 0.001".

Source

pub fn with_legend(self, label: impl Into<String>) -> Self

Attach a legend to this plot (shows one entry per group).

Trait Implementations§

Source§

impl Default for SurvivalPlot

Source§

fn default() -> Self

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

impl From<SurvivalPlot> for Plot

Source§

fn from(p: SurvivalPlot) -> Self

Converts to this type from the input type.

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> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.