Skip to content

Instantly share code, notes, and snippets.

@giovannotti
Last active February 9, 2018 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovannotti/d85828d9d7afbdece45bc39669154a07 to your computer and use it in GitHub Desktop.
Save giovannotti/d85828d9d7afbdece45bc39669154a07 to your computer and use it in GitHub Desktop.
Change plot colors according to RStudio theme in .Rprofile
# 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