DataExplorer icon indicating copy to clipboard operation
DataExplorer copied to clipboard

Using global options for ggthemes in individual plots

Open TarjinderSingh opened this issue 4 years ago • 4 comments

When using individual functions like plot_intro(data), it seems like ggplot2::theme_set doesn't apply in changing the theme used. Is it possible for individual functions to inherit theme_set, or for us to set a DataExplorer::ggthemes default in options()?

TarjinderSingh avatar Aug 22 '21 00:08 TarjinderSingh

I am not sure if I am following, but the following code works for me in applying a theme:

library(DataExplorer)
library(ggplot2)
plot_intro(iris, ggtheme = theme_minimal())
plot_intro(iris, ggtheme = theme_void())

boxuancui avatar Aug 22 '21 14:08 boxuancui

Yes, that works for me too, but I was wondering if there is a way to set the theme once for all DataExplorer plots. Set a default so we don't need to provide the argument every time. For instance, we may just want to use theme_minimal for all our plots. Thanks!@

TarjinderSingh avatar Aug 22 '21 15:08 TarjinderSingh

Thanks! I see what you meant. Unfortunately, I don't think it is possible to store theme options, because themes are applied and then overwritten at the very last step. Since we apply the default theme, it will always be set back to theme_gray() if nothing is specified.

However, a quick workaround could be wrappers around the plot functions. Something like this should work:

plot_*_theme <- function(...) plot_*(..., ggtheme = your_desired_theme())

## e.g., with plot_intro
plot_intro_void <- function(...) plot_intro(..., ggtheme = theme_void())
plot_intro_void(iris)

Hope that helps!

boxuancui avatar Aug 22 '21 15:08 boxuancui

I see - thanks! I wonder if it is possible to allow ggtheme to be something we can set as a global options. ie options(DataExplorer.ggtheme=theme_void()). That way, it may be compatible with how the functions are currently coded. In any case, I can make it work. Thanks!

TarjinderSingh avatar Aug 22 '21 21:08 TarjinderSingh