Expand formula interface to aesthetics, facets, labels, and encode#36
Merged
Expand formula interface to aesthetics, facets, labels, and encode#36
Conversation
Replace character string aesthetics (x = 'col', y = 'col', color = 'col') with the formula interface (y ~ x, color = ~ col) in all @examples sections across R source files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: yihui <163582+yihui@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: yihui <163582+yihui@users.noreply.github.com>
- Convert g2(data, x = 'X', y = 'Y') to g2(data, Y ~ X) in all R code chunks - Convert g2(data, x = 'X') to g2(data, ~ X) for x-only mappings - Convert color/size/shape/opacity = 'var' to use ~ var formula syntax - Convert facet_rect(x = 'var') to facet_rect(x = ~ var) - Convert facet_circle(position = 'var') to facet_circle(position = ~ var) - Convert labels_(text = 'var') to labels_(text = ~ var) - Convert encode(x = 'x', y = 'y') standalone calls to use ~ formulas - Update vignette to lead with formula interface in Data and encodings section - Add Character string interface subsection documenting the string API - Keep encode = list(...) inside mark_*() calls unchanged (not aesthetic mappings) - Keep reactive Shiny inputs (input$xvar) as string-based (formula not applicable) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: yihui <163582+yihui@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yihui/gglite/sessions/5e1930eb-44f0-4bc1-af76-c246efa635c5 Co-authored-by: yihui <163582+yihui@users.noreply.github.com>
Agent-Logs-Url: https://github.com/yihui/gglite/sessions/5e1930eb-44f0-4bc1-af76-c246efa635c5 Co-authored-by: yihui <163582+yihui@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
yihui
April 8, 2026 18:08
View session
yihui
approved these changes
Apr 8, 2026
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.
Summary
Expands the formula shorthand
~ varto work in all aesthetic mappings and variable-name arguments throughout the package.What changed
Core implementation (
R/utils.R,R/gglite.R,R/facet.R,R/component.R):as_var()utility converts a one-sided single-term formula~ varto the character string"var"; all other values pass through unchangedg2(): named aesthetic arguments now accept~ varformulas (e.g.,color = ~ species); the positional-formula detection is fixed to only trigger for the unnamed first argumentencode(): all arguments accept~ varformulasfacet_rect()/facet_circle(): variable arguments accept~ varformulaslabels_(): thetextargument (and all options) accept~ varformulasUsage
Documentation updates
@examplesin R source files updated to use the formula interfaceexamples/*.Rmdfiles updated to use the formula interfacevignettes/gglite.Rmdupdated to lead with the formula interface and document the character string interface as an alternative in a dedicated subsectionTests added
g2()with all-named formula aesthetics (x = ~ mpg, y = ~ hp, color = ~ cyl)g2()with mixed positional formula + formula aesthetic (hp ~ mpg, color = ~ cyl)encode()with formula aestheticsfacet_rect()andfacet_circle()with formula variableslabels_()withtext = ~ varas_var()error on multi-term formula