Skip to content

Add paired_raincloud() for repeated-measures connecting lines - #57

Open
pengkodammaya wants to merge 2 commits into
pog87:masterfrom
pengkodammaya:feat/repeated-measures
Open

Add paired_raincloud() for repeated-measures connecting lines#57
pengkodammaya wants to merge 2 commits into
pog87:masterfrom
pengkodammaya:feat/repeated-measures

Conversation

@pengkodammaya

Copy link
Copy Markdown

Closes #56.

What

Implements the repeated-measures roadmap item as a dedicated function,
paired_raincloud() (per the design discussion on the issue — keeping
RainCloud's signature untouched). It draws a standard raincloud and connects
each subject's rain points across categories, making within-subject change
visible for paired / pre-post / longitudinal designs.

import ptitprince as pt

pt.paired_raincloud(
    x="condition", y="score", data=df, orient="h",
    id="subject",                                        # subject identifier column
    line_color="gray", line_alpha=0.3, line_width=0.5,   # line styling
)

Paired raincloud: 30 subjects, pre to post, each connected by a line

Pre→post on 30 subjects: each thin line is one subject, so within-subject change is visible on top of the group distributions.

How

  • paired_raincloud() wraps RainCloud() — it calls it for all the existing
    cloud/box/rain drawing (so styling stays identical and in one place), then adds
    the connecting lines on top. RainCloud itself is not modified at all.
  • The rain is drawn by the existing stripplot; seaborn doesn't expose the
    jittered coordinates, so a private helper _draw_repeated_measures_lines()
    recovers them from the rain PathCollection offsets (the cloud is a
    PolyCollection and the box is patches/lines, so the rain is the only
    PathCollection added) and matches each point back to its subject using the
    within-category row order of data, which seaborn preserves.
  • NaN measurements are filtered to keep that row-order matching aligned with the
    points seaborn actually drew, so a missing observation simply breaks that
    subject's line instead of misaligning everything.

Scope / limitations (v1)

  • Supports the no-hue / no-dodge case (the overwhelmingly common one).
  • hue / dodge are not accepted — with dodged sub-groups the
    point→subject mapping is ambiguous, so they raise a clear ValueError rather
    than silently drawing something wrong. Extending to dodged sub-groups is a
    sensible follow-up.

Backwards compatibility

Purely additive — a new function plus a private helper. RainCloud is untouched,
so existing behaviour is byte-for-byte unchanged.

Standard raincloud: unchanged behaviour

RainCloud output is exactly as before.

Tests

Adds TestPairedRaincloud (+ a paired_data fixture in conftest.py):

  • one line per subject, horizontal and vertical;
  • a plain RainCloud draws no per-subject lines;
  • NaN measurements don't error;
  • hue / dodge raise ValueError;
  • non-column-name inputs raise;
  • line-style kwargs accepted; styling kwargs (move, point_size) forward to RainCloud.

All green locally on seaborn 0.13.2 / matplotlib 3.x.

Docs

  • New function carries a full docstring (id / line_color / line_alpha / line_width).
  • Adds a standalone repeated-measures tutorial notebook
    (tutorial_python/tutorial_repeated_measures.ipynb) using the existing Bristol
    AnxietyPaper dataset — which is already repeated-measures, so the feature
    drops straight in.

AnxietyPaper: within-participant sensitivity across four emotion conditions

The feature on the tutorial's own AnxietyPaper data: each participant connected across the four emotion conditions.

peyterho added 2 commits June 17, 2026 07:24
Implements the repeated-measures roadmap item as a dedicated function,
paired_raincloud(), rather than new parameters on RainCloud (per the
design discussion on the issue). It wraps RainCloud for the standard
cloud/box/rain drawing, then connects each subject's rain points across
categories for paired / pre-post / longitudinal data.

RainCloud itself is unchanged. hue/dodge raise ValueError, since the
point-to-subject mapping is ambiguous with dodged sub-groups.

Adds the _draw_repeated_measures_lines helper, the paired_data fixture,
the TestPairedRaincloud test class, and a standalone tutorial notebook
on the AnxietyPaper dataset.

Drafted with assistance from Claude (Anthropic).
Example renders embedded in the PR write-up: the pre/post paired demo,
the AnxietyPaper tutorial data with connecting lines, and a standard
RainCloud showing unchanged behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the repeated-measures feature: connecting lines for paired data

2 participants