-
Notifications
You must be signed in to change notification settings - Fork 1
Support | 0 + var for row faceting in formula syntax
#19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,8 @@ extract_terms = function(expr) { | |
| #' - `y ~ x` maps to `list(x = 'x', y = 'y')` | ||
| #' - `~ x` maps to `list(x = 'x')` | ||
| #' - `~ x1 + x2 + x3` maps to `list(position = c('x1', 'x2', 'x3'))` | ||
| #' - `y ~ x | z` adds faceting by `z` | ||
| #' - `y ~ x | z` adds faceting by `z` (columns) | ||
| #' - `y ~ x | 0 + z` adds faceting by `z` (rows) | ||
| #' - `y ~ x | z1 + z2` adds faceting by `z1` (columns) and `z2` (rows) | ||
|
Comment on lines
118
to
123
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these need to be mentioned in the vignette, and ideally also give examples for each case (can use penguins data since it has multiple categorical variables)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added formula faceting examples to the vignette's Facets section using penguins data — column facet ( |
||
| #' | ||
| #' @param f A formula object. | ||
|
|
@@ -147,13 +148,17 @@ parse_formula = function(f) { | |
| aesthetics$position = rhs_terms | ||
| } | ||
|
|
||
| # Build facet | ||
| # Build facet: | var → column; | 0 + var → row; | var1 + var2 → both | ||
| facet = NULL | ||
| if (length(facet_terms)) { | ||
| enc = list() | ||
| if (length(facet_terms) >= 1) enc$x = facet_terms[1] | ||
| if (length(facet_terms) >= 2) enc$y = facet_terms[2] | ||
| facet = list(type = 'facetRect', encode = enc) | ||
| row_only = facet_terms[1] == '0' | ||
| if (row_only) facet_terms = facet_terms[-1] | ||
| if (length(facet_terms) >= 1) { | ||
| if (row_only) enc$y = facet_terms[1] else enc$x = facet_terms[1] | ||
| } | ||
| if (!row_only && length(facet_terms) >= 2) enc$y = facet_terms[2] | ||
| if (length(enc)) facet = list(type = 'facetRect', encode = enc) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make this code more compact? the logic is not easy to digest
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified to 4 lines using |
||
| } | ||
|
|
||
| list(aesthetics = aesthetics, facet = facet) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
follow copilot instructions: don't include news for v0.1 after each PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted NEWS.md to original state in 807ffb1.