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
ggplot2 allows argument splicing in many places. Prime examples are
aes(!!!x)orgeom_point(,,,,!!!x). (Admittedly, the point example is a bit awkward). However, we cannot splice arguments intheme().I think it might be nice, if the following code:
Would give a plot like this:
Created on 2023-11-28 with reprex v2.0.2