Axis alignment over multiple panels #5826
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proof-of-concept PR exploring to fix #5820.
Briefly, this PR adds extra spacers to the axis gtable that have 'null' units so that the spacers take up the 'available' space. This works to align labels across panels as 'available space' is flexible and adapts to the size of the cell in the plot's gtable, which is always* based on the largest axis.
* See caveat below
I consider this PR a POC because this solution is not perfect. In some circumstances, the plot's gtable cell size allocated to axes is smaller than the actual axis size, in particular when
facet_wrap()
has ragged panels that need to be labelled on the ragged ends. In the plot below, notice that the right axis of the bottom-middle panel is misplaced and also the bottom axis of the top-right panel is misplaced.Created on 2024-04-04 with reprex v2.1.0
However, the axis doesn't know when it will be placed in smaller cells and installing the plumbing to let the axis know would require tempering with already very complicated code that places back axes. Unless I can find some trick to mitigate this problem, I'm stuck at this 90% solution, which is why I wouldn't merge this PR for now.