Hello folks,
Correct me if I'm wrong, but I don't believe there is a way to detect whether a user has a global ggplot2 theme set. The closest I can get, I think, is something like:
user_has_set_theme <- function() {
!identical(ggplot2::get_theme(), ggplot2::theme_gray())
}
This covers almost all cases, except where the user specifically wants theme_gray()!
My use case is writing a package which produces ggplot2 figures. By default we choose a nice theme that is appropriate for each plot type, but I'm keen that advanced users can escape this default theming if they do have a global theme set. The above user_has_theme_set() function does the job in all cases - e.g., if they set theme_minimal() or some other theme as their global theme - except that where the user really wants to use that default gray theme.
The only discussion I can find on this topic is https://forum.posit.co/t/how-to-check-if-the-user-has-set-a-global-ggplot-theme-with-theme-set-or-not/129162/4 where this "check against theme_grey" is advised.
Cheers!
Hello folks,
Correct me if I'm wrong, but I don't believe there is a way to detect whether a user has a global ggplot2 theme set. The closest I can get, I think, is something like:
This covers almost all cases, except where the user specifically wants
theme_gray()!My use case is writing a package which produces
ggplot2figures. By default we choose a nice theme that is appropriate for each plot type, but I'm keen that advanced users can escape this default theming if they do have a global theme set. The aboveuser_has_theme_set()function does the job in all cases - e.g., if they settheme_minimal()or some other theme as their global theme - except that where the user really wants to use that default gray theme.The only discussion I can find on this topic is https://forum.posit.co/t/how-to-check-if-the-user-has-set-a-global-ggplot-theme-with-theme-set-or-not/129162/4 where this "check against theme_grey" is advised.
Cheers!