if (!require(ggplot2)) install.packages('ggplot2') if (!require(extrafont)) install.packages('extrafont') library(ggplot2) library(extrafont) # **************** Base theme ************************************* base_theme <- theme( plot.margin = unit(rep(1, 4), "cm"), plot.title = element_text(size = 24, face = "bold", color = "#22292F", margin = margin(b = 8)), plot.subtitle = element_text(size = 16, lineheight = 1.1, color = "#22292F", margin = margin(b = 25)), plot.caption = element_text(size = 12, margin = margin(t = 25), color = "#3D4852"), axis.title.x = element_text(margin = margin(t = 15)), axis.title.y = element_text(margin = margin(r = 15)), axis.text = element_text(color = "#22292F") ) set_base_theme <- function() { theme_set(theme_minimal(base_size = 18) + base_theme) } # ***************** Set flat theme ******************************** flat_theme <- theme( panel.background = element_rect(fill = "#f3f6f6", color = NA), panel.grid = element_line(color = "#cacfd2", linetype = "dashed"), axis.line = element_line(color = "#606F7B") ) set_flat_theme <- function() { theme_set(theme_minimal(base_size = 18, base_family = "Segoe UI") + base_theme + flat_theme) } # *************** Dark theme *************************************** dark_theme_two <- theme( text = element_text(family = "Segoe UI"), plot.margin = unit(rep(1, 4), "cm"), plot.title = element_text(size = 24, face = "bold", color = "#22292F", margin = margin(b = 8)), plot.subtitle = element_text(size = 16, lineheight = 1.1, color = "#22292F", margin = margin(b = 25)), plot.caption = element_text(size = 12, margin = margin(t = 25), color = "#3D4852"), axis.title.x = element_text(margin = margin(t = 15)), axis.title.y = element_text(margin = margin(r = 15)), axis.text = element_text(color = "#22292F"), panel.background = element_rect("#34495e", color = NA), panel.grid = element_line(color = "#49637a") ) set_dark_theme <- function() { theme_set(theme_minimal(base_size = 18, base_family = "Segoe UI") + dark_theme_two) }