You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
There's a longstanding PR (#2749) that I believe would provide the features you need (though using a somewhat different approach). It was never completed because there are some difficult technical issues that we couldn't resolve and where any resolution we could think of would cause a breaking change. Hopefully some day we can get this done.
That would get most the way there, but wouldn't for example, permit the first example there (make the lines of the histogram bars the same color as the panel background)
Agree that it is only partly what you ask for, but it is very akin in spirit and its unlikely we will add one thing without the other... when it may happen is still up in the air, though
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:
Potentially related to #2691
The text was updated successfully, but these errors were encountered: