plotters-statistical 0.1.0

Statistical chart primitives (box, violin, ROC, PR, regularization-path, residual) as native plotters series
Documentation
//! Missingness heatmap figure rendered to `missingness_heatmap.svg`.

use plotters::prelude::*;
use plotters_statistical::MissingnessHeatmap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root = SVGBackend::new("missingness_heatmap.svg", (720, 520)).into_drawing_area();
    root.fill(&WHITE)?;

    // Six variables with different, structured missingness patterns.
    let n = 300;
    let mut columns: Vec<Vec<Option<f64>>> = Vec::new();
    // id: complete
    columns.push((0..n).map(|i| Some(i as f64)).collect());
    // age: ~5% missing, scattered
    columns.push(
        (0..n)
            .map(|i| if i % 20 == 7 { None } else { Some(30.0) })
            .collect(),
    );
    // income: missing for the first third (e.g. a late-added field)
    columns.push(
        (0..n)
            .map(|i| if i < n / 3 { None } else { Some(50.0) })
            .collect(),
    );
    // score: ~40% missing
    columns.push(
        (0..n)
            .map(|i| if i % 5 < 2 { None } else { Some(0.5) })
            .collect(),
    );
    // region: complete
    columns.push((0..n).map(|_| Some(1.0)).collect());
    // note: mostly missing
    columns.push(
        (0..n)
            .map(|i| if i % 10 == 0 { Some(1.0) } else { None })
            .collect(),
    );

    let labels = ["id", "age", "income", "score", "region", "note"]
        .iter()
        .map(|s| s.to_string())
        .collect();

    MissingnessHeatmap::from_columns(&columns, labels)?
        .title("Missing data by column")
        .draw(&root)?;

    root.present()?;
    println!("wrote missingness_heatmap.svg");
    Ok(())
}