Repository navigation
Fix free space in facets with radial, polar and sf coords (#6360) - #6924
Open
josefelipe0036 wants to merge 1 commit into
Open
josefelipe0036 wants to merge 1 commit into
josefelipe0036 wants to merge 1 commit into
Conversation
…6360) For free `space`, `Facet$init_gtable()` sized panels with `diff(ranges[[i]]$x.range)` (and `y.range`). The panel parameters of `coord_radial()`, `coord_polar()` and `coord_sf()` don't have these fields, so `vapply()` failed with "values must be length 1, but FUN(X[[1]]) result is length 0" for `facet_wrap()` and `facet_grid()`. `Facet$draw_panels()` now falls back to fixed space with a warning that names the facet and the coordinate system when the ranges are missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
josefelipe0036
marked this pull request as ready for review
November 7, 2026 01:22
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6360.
Root cause
For free
space,Facet$init_gtable()sizes each panel withdiff(ranges[[i]]$x.range)(ory.range). The panel parameters ofcoord_radial()andcoord_polar()usetheta.range/r.rangeinstead, andcoord_sf()usesx_range/y_range, sodiff(NULL)returnsnumeric(0)andvapply()fails with an error that mentions neither the facet nor the coord:facet_wrap()andfacet_grid()shareFacet$draw_panels(), so both fail, forspace = "free_x","free_y"and"free", and the problem isn't limited tocoord_radial():coord_polar()andcoord_sf()fail the same way.Fix
Facet$draw_panels()now checks that the panel parameters have a position range in the free direction. If they don't, it warns and falls back to fixed space:As discussed in the issue, this no longer throws an error, and it doesn't try to give
spacea meaning in polar coordinates, where the panel aspect ratio follows the bounding box of the arc rather than the data range. Coords that havex.range/y.range(coord_cartesian(),coord_transform(),coord_flip(),coord_map(), ...) are unaffected: only combinations that used to error behave differently.Reprex
facet_wrap(space = "free_x")+coord_radial())facet_wrap(space = "free_y")+coord_radial()facet_grid(space = "free_x")+coord_radial()facet_grid(scales = "free", space = "free")+coord_radial()facet_grid(space = "free_x")+coord_polar()facet_grid(space = "free_x")+coord_sf()facet_grid(scales = "free_x", space = "free_x")+ Cartesian,coord_transform(),coord_flip()Tests
New test in
test-facet-.R:expect_doppelganger()insideexpect_snapshot_warning(), following the pattern intest-geom-path.R);space = "fixed"forfacet_wrap()+coord_radial(),facet_grid()+coord_polar(),facet_grid()+coord_sf(), and a facet factor with an unused level and anNA(drop = FALSE, so one panel is empty) +coord_radial().The test fails on main with the error above and passes with this change.
Run locally on R 4.6.0 (Windows 11):
devtools::test(): 2988 expectations, 0 failures, 0 errors, 0 warnings, 0 skips.devtools::check(document = TRUE, args = "--no-manual"): 0 errors | 0 warnings | 1 note. The note (checking Rd metadata:Rd files without \alias: 'shared_layer_parameters.Rd') comes fromman/shared_layer_parameters.Rd, which this PR doesn't touch, so it is also present on main.Note: help with this issue was offered in March 2025, but there has been no activity on it since. Happy to step back if someone is already working on it.
🤖 Generated with Claude Code