Skip to content

fix(plot): ensure correct per-facet axis bounds assignment in scatter plots (#140)#141

Merged
sbuis merged 3 commits into
mainfrom
fix/140-scatter-axis-bounds-ordering
Feb 20, 2026
Merged

fix(plot): ensure correct per-facet axis bounds assignment in scatter plots (#140)#141
sbuis merged 3 commits into
mainfrom
fix/140-scatter-axis-bounds-ordering

Conversation

@sbuis
Copy link
Copy Markdown
Member

@sbuis sbuis commented Feb 20, 2026

Summary

Fix incorrect axis bounds assignment in plot() scatter panels caused by inconsistent
ordering between computed variable bounds and actual facet display order.

Problem

Axis limits were computed per variable using grouped data, but applied to facets
by positional index. When the ordering of variables in the data differed from
the facet display order in the ggplot object, axis limits were assigned to the
wrong panels.

This resulted in mismatched axis scaling across facets.

Root Cause

  • compute_axis_bounds() returned unnamed vectors.
  • make_axis_square() and force_y_axis() relied on positional matching.
  • Facet order in ggplot depends on factor levels and plot build layout,
    which may differ from grouped data order.

Changes

  • compute_axis_bounds() now returns named vectors indexed by variable name.
  • Added internal helper get_facet_order() to retrieve actual facet layout
    order using ggplot_build().
  • Updated make_axis_square() to reorder axis bounds according to
    the real facet display order.
  • Updated force_y_axis() to apply the same logic.
  • Removed implicit dependence on positional indexing.

Closes #140.

@github-actions
Copy link
Copy Markdown

📝 Styler has automatically formatted the following R files in this PR:

  • R/specific_plotting_scatter.R

Please pull these changes to your local branch.

@sbuis sbuis merged commit b1a44b4 into main Feb 20, 2026
@sbuis sbuis deleted the fix/140-scatter-axis-bounds-ordering branch February 20, 2026 15:52
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.

Incorrect axis bounds assignment in plot() (scatter) due to inconsistent variable ordering

1 participant