Support | 0 + var for row faceting in formula syntax#19
Conversation
Agent-Logs-Url: https://github.com/yihui/gglite/sessions/3a6cd822-fa4d-4ac0-b226-eee4af9726f3 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yihui/gglite/sessions/3a6cd822-fa4d-4ac0-b226-eee4af9726f3 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
| #' - `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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Added formula faceting examples to the vignette's Facets section using penguins data — column facet (| species), row facet (| 0 + island), and both (| species + island). See 807ffb1.
| - The formula syntax in `g2()` now supports `| 0 + var` for row faceting (e.g., | ||
| `y ~ x | 0 + var`), in addition to the existing `| var` for column faceting. | ||
|
|
There was a problem hiding this comment.
follow copilot instructions: don't include news for v0.1 after each PR
There was a problem hiding this comment.
Reverted NEWS.md to original state in 807ffb1.
| 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) |
There was a problem hiding this comment.
can you make this code more compact? the logic is not easy to digest
There was a problem hiding this comment.
Simplified to 4 lines using setNames + head — a leading '0' sets names to 'y', otherwise c('x', 'y'), then terms are matched to names by position. See 807ffb1.
…e examples Agent-Logs-Url: https://github.com/yihui/gglite/sessions/a4f72763-bd38-4357-afa0-7214c0c67f75 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
Extends the formula interface in
g2()so that| 0 + varproduces a row facet (encode$y), mirroring the R convention where0suppresses the default (column) term.| var→ column facet (encode$x) — unchanged| 0 + var→ row facet (encode$y) — new| var1 + var2→ both — unchangedChanges
parse_formula()detects leading'0'in facet terms and shifts encoding fromxtoy. Bare| 0(no variable after) is handled gracefully — no facet is created.| 0 + varand the| 0edge case.| species), row facet (| 0 + island), and both (| species + island).