Last active
February 9, 2018 12:46
Change plot colors according to RStudio theme in .Rprofile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# RStudio theme | |
rstudio_theme <- "Twilight" | |
if(interactive()){ | |
library(dplyr) | |
library(ggplot2) | |
library(editheme) | |
# RStudio theme as base plot color | |
addTaskCallback(function(...) { | |
set_base_sty(rstudio_theme, variation = 1) | |
return(FALSE) | |
}) | |
# RStudio theme as ggplot default color/fill | |
ggplot_geoms <- ls("package:ggplot2") %>% .[grep("^geom", .)] %>% stringr::str_extract(., "(?<=_).*$") %>% .[-grep("blank", .)] | |
for (i in ggplot_geoms) { | |
try(update_geom_defaults(geom = i, new = list(colour = get_pal(rstudio_theme)[1])), silent = TRUE) | |
} | |
# RStudio theme as ggplot default theme | |
ggplot2::theme_set(theme_editor(rstudio_theme)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment