Skip to content

Dodge and jitter position adjustments don't account for facet panels #254

@cpsievert

Description

@cpsievert

Problem

Similar to the stacking issue fixed in #244, dodge and jitter position adjustments compute group indices from the full DataFrame without accounting for facet panels. Since facet columns are included in partition_by (via add_discrete_columns_to_partition_by), compute_group_indices sees composite groups across facet panels rather than the groups within each panel.

Dodge

compute_group_indices(&df, &layer.partition_by) in dodge.rs:161 creates composite keys from all partition_by columns including facet columns. With fill=["X","Y"] and facet=["F1","F2"], dodge computes n_groups=4 (X-F1, X-F2, Y-F1, Y-F2) instead of the correct n_groups=2 (X, Y) per panel. This makes bars too narrow and offsets incorrect.

Jitter

Same issue when dodge=truecompute_group_indices(&df, &layer.partition_by) at jitter.rs:487 inflates the group count, producing incorrect dodge offsets.

Root cause

partition_by conflates two different kinds of columns:

  1. Grouping columns (fill, color) — used by dodge/jitter to determine n_groups
  2. Panel columns (facet1, facet2) — should reset computations per panel, not inflate group count

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions