Control axes padding:xpad & ypad - #729
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Flipped boxplots and flipped plots using tpar() defaults currently apply padding to the wrong physical axis.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds configurable x/y-axis padding while preserving base R defaults when unset.
Changes:
- Adds
xpad/ypadarguments andtpar()support. - Applies padding across standard, flipped, logged, and faceted plots.
- Adds documentation and coordinate-based tests.
File summaries
| File | Description |
|---|---|
R/tpar.R |
Registers and validates global padding settings. |
R/tinyplot.R |
Exposes and propagates padding arguments. |
R/tinyAxis.R |
Accounts for pre-expanded limits. |
R/lim.R |
Calculates padded axis limits. |
R/flip.R |
Swaps padding when axes are flipped. |
R/facet.R |
Applies padding to facet windows. |
NEWS.md |
Announces the feature. |
man/tpar.Rd |
Documents global settings. |
man/tinyplot.Rd |
Documents public arguments. |
man/facet.Rd |
Updates internal function usage. |
inst/tinytest/test-axis-pad.R |
Tests padding and validation. |
Review details
Files not reviewed (3)
- man/facet.Rd: Generated file
- man/tinyplot.Rd: Generated file
- man/tpar.Rd: Generated file
Suppressed comments (1)
R/lim.R:63
- This validation accepts
Inf, butexpand_lim()then returns the unexpanded limits for a non-finite pad while downstream code still forcesxaxs/yaxs = "i". Thusxpad = Infsilently produces a tight axis instead of either padding or rejecting the value. Require finite padding values explicitly.
assert_numeric(xpad, len = 1, lower = 0, null.ok = TRUE, name = "xpad")
assert_numeric(ypad, len = 1, lower = 0, null.ok = TRUE, name = "ypad")
- Files reviewed: 8/11 changed files
- Comments generated: 5
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Closes #662
This PR adds the new top-level
tinyplot(..., x/ypad)args for fine-grained control of the how much padding is added to ends of the axes.If left as
NULL, then behaviour falls back to standard base R conventions, e.g. governed bypar("xaxs"). In most cases this translates to a 0.04 (4%) padding exanpsion on each end of the axes.(Aside: I initially wanted to call them
xaxpandyaxp, but those arguments are already reserved bypar.)MWE
Etc.Created on 2026-09-12 with reprex v2.1.1
FYI @strengejacke.
P.S. I'm also considering changing (increasing) the default padding for categorical axes, but that will come in a follow-up PR.