Skip to content

Should theme() support argument splicing? #5542

Description

@teunbrand

ggplot2 allows argument splicing in many places. Prime examples are aes(!!!x) or geom_point(,,,,!!!x). (Admittedly, the point example is a bit awkward). However, we cannot splice arguments in theme().

I think it might be nice, if the following code:

library(ggplot2)

red_axis <- list(
  axis.line = element_line(colour = "red"),
  axis.text = element_text(colour = "red"),
  axis.ticks = element_line(colour = "red"),
  axis.title = element_text(colour = "red")
)

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  theme(!!!red_axis)
#> Error in !red_axis: invalid argument type

Would give a plot like this:

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  rlang::inject(theme(!!!red_axis))

Created on 2023-11-28 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions