Skip to content

Should theme() support argument splicing? #5542

Closed
@teunbrand

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

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