Skip to content

New faceting syntax#147

Merged
thomasp85 merged 17 commits intoposit-dev:mainfrom
thomasp85:issue6-faceting
Feb 23, 2026
Merged

New faceting syntax#147
thomasp85 merged 17 commits intoposit-dev:mainfrom
thomasp85:issue6-faceting

Conversation

@thomasp85
Copy link
Collaborator

Fix #6

This PR massively rewrites the faceting clause, allowing scaling of faceting variables, mapping inside layers to overwrite the default, repeating of layers missing faceting variables, and a lot of other stuff

The docs are there to describe the new functionality

@thomasp85 thomasp85 requested a review from teunbrand February 20, 2026 14:10
Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, I really like having facet aesthetics and handle their formatting by scales. Most comments below are nitpicks that you can ignore, but there are a few topics I'd want to raise.

I'm tempted to suggest that SETTING scales => 'free' should live in coords.

Previously the facet writer logic wasn't complicated enough to merit a module on its own, whereas I think it has become too large to live in the writer's mod.rs file and it should live in its own file.

I don't like the RENAMING clause as part of the facet. If we just have it in scales, there is a single source of truth for the renaming which will lead to less confusion because people don't have to think about precedence. Moreover, it currently duplicates a bunch of logic which makes maintenance worse for (in my eyes) identical functionality. Even if you have strong reasons for keeping it, deduplicating the logic may be worth it in the long run.

Comment on lines +151 to +152
free_x: bool,
free_y: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we shouldn't create another context object to capture additional arguments to build_layers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it is beginning to grow out of hand. Do you propose a struct only for free_x/free_y for now? I feel the other arguments are proper first class information

'fixed', 'free', 'free_x', 'free_y'
// RENAMING clause for facet strip labels
// Syntax: RENAMING 'A' => 'Alpha', 'B' => 'Beta', * => 'Region: {}'
facet_renaming_clause: $ => seq(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, if we want to keep facet renaming open, can't we re-use the scale_renaming_clause or rename to renaming_clause and use in both places?

@thomasp85
Copy link
Collaborator Author

Just to comment on the two overarching questions.

I don't think scales should live in coords. We are even removing the xlim/ylim settings there. The behaviour of scales across panels is, well, related to panels which is a feature of the faceting

I have gone back and forth when it comes to removing RENAMING. The only reason it still exist is because it might be nice to be able to set a common formatter for all (both) rather than having to define an explicit scale for them... But I can easily be persuaded otherwise

@teunbrand
Copy link
Collaborator

I have gone back and forth when it comes to removing RENAMING. The only reason it still exist is because it might be nice to be able to set a common formatter for all (both) rather than having to define an explicit scale for them... But I can easily be persuaded otherwise

Hmm I hear you, but I think the scope of that use case is relatively narrow. The case where this might be useful is (1) if you use a grid layout and (2) if you have variables that need formatting and (3) both variables should be formatted in the same way. I don't see ggplot2::facet_grid(labeller) used in the wild a whole lot either (but that may also be because it is tedious to use).

@thomasp85 thomasp85 merged commit 850a362 into posit-dev:main Feb 23, 2026
17 checks passed
@thomasp85 thomasp85 deleted the issue6-faceting branch February 23, 2026 13:23
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.

Faceting syntax needs improving

2 participants