pipette
ESEspañol

Contrast-Aware Annotation for Statistical Graphics: The ggtwotone Package for ggplot2

Beenu Sareena, Heike Hofmann

Preprint

In the authors' words

Readable annotations are essential for interpreting statistical graphics, yet conventional single-color lines and labels can lose visibility when they cross backgrounds with heterogeneous luminance. We introduce a contrast-aware annotation framework implemented in the ggtwotone R package for ggplot2. The framework combines dual-stroke rendering, adaptive text-color selection, and perceptually guided highlight palettes to improve annotation visibility across light and dark regions. A shared contrast-adjustment engine supports WCAG- and APCA-based contrast criteria, reducing the need for manual color adjustment. The package provides contrast-aware geoms for segments, curves, paths, mathematical functions, regression overlays, and text while remaining compatible with standard ggplot2 workflows. A simulation-based evaluation across heterogeneous background colors demonstrates improved worst-case contrast for dual-stroke annotations and adaptive text selection, while also identifying trade-offs in perceptual separation as the number of requested highlight colors increases. Applications to statistical graphics and scientific images illustrate the framework in practical visualization settings. Together, these tools provide a reproducible approach for incorporating contrast considerations directly into graphical annotation.

Main resultLimitation the authors admit

Appeared: Monday, September 28. arXiv. Preprint, not yet peer-reviewed.

Authors' comment: 27 pages, 11 figures, 5 tables. Extended version of a student paper recognized with an ASA Statistical Computing and Graphics Student Paper Award. R package available on CRAN