-
Thanks for creating this package, which I'm hoping to use alongside the excellent {targets} package to speed up some pipelines. I'm having difficulty setting a global {ggplot2} theme when using I assume this might be something to do with the I tried setting (By the way, I'm using the version from the current
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think this is because > ggplot2::theme_set
function (new)
{
old <- ggplot_global$theme_current
ggplot_global$theme_current <- new
invisible(old)
} On each worker, library(targets)
library(crew)
library(ggplot2)
tar_option_set(
controller = crew_controller_local()
)
set_theme <- function() {
theme_set(theme_dark())
}
list(
tar_target(
name = plot_file,
command = {
set_theme()
ggsave(
"plot.png",
ggplot(iris, aes(Sepal.Width, Sepal.Length)) + geom_point()
)
},
format = "file"
)
) If you have many such targets, then |
Beta Was this translation helpful? Give feedback.
-
Brilliant, thanks. |
Beta Was this translation helpful? Give feedback.
I think this is because
ggplot2::theme_set()
sets the theme in a local package environment insideggplot2
instead the environment thattargets
ships to the workers (tar_option_get("envir")
, which is usually.GlobalEnv
).On each worker,
ggplot2
is loaded from scratch and does not know the modifications to theggplot_global
object hidden inside theggplot2
package environment. As an alternative, you could encapsulatetheme_set()
inside a global function and then call it in each ggplot target.