-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
In a package I'm developing, I would occasionally like to set geom parameters, such as colors, to have the same values as theme elements. For example, to use the same color for geom_line() as for the axis lines or the panel background. I would like to be able to set this while still allowing the theme to be changed later, with the geom parameters changing to match. It would be really helpful to have a .theme
pronoun that could refer to whatever theme is set for a plot.
Example:
library(ggplot2)
# set line colors to match panel backgound
ggplot(mtcars) +
aes(x = mpg) +
geom_histogram(
color = .theme$panel.background$fill
# currently must be:
# color = theme_bw()$panel.background$fill
) +
theme_bw()
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# set line color to match theme line colors
ggplot(mtcars) +
aes(x = disp, y = mpg) +
geom_point() +
geom_smooth(
se = FALSE,
color = .theme$line$colour
# currently must be:
# color = ggthemes::theme_economist()$line$colour
) +
ggthemes::theme_economist()
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
Potentially related to #2691
olivermagnanimous