Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Merge additional label_glue() functionality from stickylabeller package #499

@jimjam-slam

Description

@jimjam-slam

Scales 1.4.0, via #459, adds label_glue() to construct labels using the glue package. My stickylabeller package offers similar functionality, but we add some additional row-index columns to the input data to facilitate numbering facets:

From the README:

  • .n numbers the facets numerically: 1, 2, 3…
  • .l numbers the facets using lowercase letters: a, b, c…
  • .L numbers the facets using uppercase letters: A, B, C…
  • .r numbers the facets using lowercase Roman numerals: i, ii, iii…
  • .R numbers the facets using uppercase Roman numerals: I, II, III…

So you can automatically number your facets like:

ggplot(mydf) +
  geom_point(aes(x = x, y = y)) +
  facet_wrap(
    vars(red, blue),
    labeller = label_glue("({.l}) Red is {toupper(red)}\nand blue is {blue}"))

Image of faceted ggplot. Each facet is labelled sequentially

This functionality is presently restricted in stickylabeller to faceting with facet_wrap(), and I understand that the addition of label_glue() in scales is likely implemented with an eye to the many other scenarios in which labelling is done (axes, other scales, etc.). Nevertheless, it's useful to have this functionality built into the labeller over pre-formatting your data, especially for interactive use.

If you're interested in integrating this functionality into scales, I'd love to retire stickylabeller and point users to scales instead! (I'll likely add a notice to stickylabeller either way, since scales is installed with ggplot2 and likely meets some users' needs without this functionality, but clearer directions to users are always nice!). Happy to put a PR together based on what else you think this might need.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions