Is it possible to check if the user has set a global ggplot theme with theme_set()
or if she is still using the default ggplot theme? If so, how?
This is relevant when one wants to create a function that returns a ggplot with a custom theme, but only if the user has not set her own theme with theme_set()
.
The idea is:
func <- function() {
p <- mtcars %>%
ggplot() +
aes(x = wt, y = mpg) +
geom_point()
if (user has not set own ggplot theme) {
p <- p + theme_custom()
return(p)
} else {
return(p)
}
}
The most elegant solution would be if there was a check_theme_set()
function that returns TRUE if the user has set her own theme with theme_set()
and FALSE if the user is still using the default ggplot theme.
(FYI, this question is inspired by: ggplot2::theme_set() doesn't work with plot_cap() and plot_cme() · Issue #212 · vincentarelbundock/marginaleffects · GitHub)