Skip to content

Instantly share code, notes, and snippets.

@mavam
Last active May 16, 2022 09:24
Show Gist options
  • Save mavam/4dc61297f478744fc3231bd5949f85f8 to your computer and use it in GitHub Desktop.
Save mavam/4dc61297f478744fc3231bd5949f85f8 to your computer and use it in GitHub Desktop.
A ggsave wrapper to store both a light and dark themed version of a plot.
# Wraps ggsave to produce both light and dark themed plot using ggdark.
dark_save <- function(filename, plot, sep = "-", ...) {
require(tools)
require(ggdark)
base <- file_path_sans_ext(filename)
ext <- file_ext(filename)
base_light <- paste(base, "light", sep = "-")
base_dark <- paste(base, "dark", sep = "-")
filename_light <- paste(base_light, ext, sep = ".")
filename_dark <- paste(base_dark, ext, sep = ".")
ggsave(filename = filename_light, plot, ...)
ggsave(filename = filename_dark, plot + dark_mode(plot$theme), ...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment