Skip to content

Control axes padding:xpad & ypad - #729

Merged
grantmcdermott merged 6 commits into
mainfrom
axis-pad
Sep 13, 2026
Merged

grantmcdermott merged 6 commits into
mainfrom
axis-pad

Conversation

@grantmcdermott

@grantmcdermott grantmcdermott commented Sep 13, 2026

Copy link
Copy Markdown
Owner

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 by par("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 xaxp and yaxp, but those arguments are already reserved by par.)

MWE

pkgload::load_all("~/Documents/Projects/tinyplot")
#> ℹ Loading tinyplot
plt(c(0,1), c(1,1)) # default x/ypad = 0.04

plt(c(0,1), c(1,1), xpad = 0.1)

plt(c(0,1), c(1,1), xpad = 0.5)

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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/ypad arguments and tpar() 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, but expand_lim() then returns the unexpanded limits for a non-finite pad while downstream code still forces xaxs/yaxs = "i". Thus xpad = Inf silently 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.

Comment thread R/facet.R Outdated
Comment thread R/lim.R Outdated
Comment thread NEWS.md Outdated
Comment thread inst/tinytest/test-axis-pad.R Outdated
Comment thread inst/tinytest/test-axis-pad.R Outdated
@grantmcdermott
grantmcdermott merged commit 26cadb2 into main Sep 13, 2026
3 checks passed
@grantmcdermott
grantmcdermott deleted the axis-pad branch September 13, 2026 16:51
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.

Add margins/paddings to the inner plot area (move categories closer together)

2 participants