Last active
January 4, 2020 13:37
-
-
Save ch-bu/8b6f4a83cbe8b15b86eeed7e0932ac60 to your computer and use it in GitHub Desktop.
Set_themes_ggplot2
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
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 = rel(1.3), | |
face = "bold", | |
color = "#22292F", | |
margin = margin(b = 8)), | |
plot.subtitle = element_text(size = rel(0.9), | |
lineheight = 1.1, | |
color = "#22292F", | |
margin = margin(b = 25)), | |
plot.caption = element_text(size = rel(0.7), | |
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_family = "Segoe UI") + | |
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 = rel(1.3), | |
face = "bold", | |
color = "#22292F", | |
margin = margin(b = 8)), | |
plot.subtitle = element_text(size = rel(0.9), | |
lineheight = 1.1, | |
color = "#22292F", | |
margin = margin(b = 25)), | |
plot.caption = element_text(size = rel(0.7), | |
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment