Skip to content

Additional facet.args for prefixing, etc. - #684

Merged
grantmcdermott merged 5 commits into
mainfrom
facet.prefix
Aug 21, 2026
Merged

Additional facet.args for prefixing, etc.#684
grantmcdermott merged 5 commits into
mainfrom
facet.prefix

Conversation

@grantmcdermott

Copy link
Copy Markdown
Owner

Closes #295

(as well as some additional, related functionality.)

This PR adds three new facet.args arguments:

  • prefix: for adding an informative prefix to facet titles a la Option to prefix facet titles with facet variable name #295.
  • labeller: for formatting facet titles via tinylabel().
  • sep: for controlling how the individual variables of a multi-variable facet title
    are separated, e.g. use sep = "\n" to stack on separate lines.

Quick MWEs

pkgload::load_all("~/Documents/Projects/tinyplot/")
#> ℹ Loading tinyplot
plt(mpg ~ wt, data = mtcars, facet = ~vs) ## base case: not very informative

plt(
  mpg ~ wt, data = mtcars,
  facet = ~vs,
  facet.args = list(prefix = TRUE)
)

plt(
  mpg ~ wt, data = mtcars,
  facet = ~vs,
  facet.args = list(
    prefix = TRUE,
    labeller = as.logical
  )
)

Special care is given over to multi-variable facet, in which case both prefix and labeller accept (named) lists to prepend/format each variable separately. Here's a kitchen sink example:

plt(
  mpg ~ wt, data = mtcars,
  facet = ~am:vs,
  facet.args = list(
    prefix = list("vs" = "V-shape", "am" = "Automatic"),
    labeller = as.logical,
    sep = "\n"
  ),
  theme = "clean"
)

Created on 2026-08-20 with reprex v2.1.1

@grantmcdermott grantmcdermott changed the title Facet.prefix Additional facet.args for prefixing, etc. Aug 21, 2026
@grantmcdermott
grantmcdermott merged commit 58cb814 into main Aug 21, 2026
3 checks passed
@grantmcdermott
grantmcdermott deleted the facet.prefix branch August 21, 2026 00:04
@jangorecki

Copy link
Copy Markdown

This is nice! Thanks

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.

Option to prefix facet titles with facet variable name

2 participants