-
Notifications
You must be signed in to change notification settings - Fork 13
/
theme_terminator.R
117 lines (108 loc) · 3.76 KB
/
theme_terminator.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
## Alex Slavenko
## theme_terminator
## 26/07/2023
# COLOR: add, remove, or edit the colors to fit your scheme (hex code preferred, but you can use any type). Names should be
#' Terminator Theme Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept terminator
#'
#' @examples
#' terminator_theme_colors
#'
terminator_theme_colors <- c(
panel = '#000000ff',
border = '#5A5A5A',
strip = '#242526',
text = '#ffffffff',
point = '#FF0000',
lighter = '#F69697',
light = '#D31A38',
medium = '#B11226',
dark = '#800808'
)
# THEME: rename function and theme() arguments according to your theme design, feel free to edit this how you would like
#' Terminator Inspired Theme
#'
#' @param terminator_font should `theme_terminator` use Google Font's IM Fell English? Default is `TRUE`.
#' @param ... additional parameters to pass to `ggplot2::theme()`
#'
#' @return a `ggplot2` `theme` element
#' @export
#' @concept terminator
#'
#' @examples
#' library(ggplot2)
#'
#' ggplot(data = data.frame(x = rnorm(50, 0, 1), y = rnorm(50,0,1)), aes(x = x, y = y)) +
#' geom_smooth(method = 'lm') +
#' geom_point(color = 'white') +
#' labs(title = 'Terminator Scatter Plot') +
#' theme_terminator()
#'
#' ggplot(mpg, aes(cty)) +
#' geom_density(aes(fill=factor(cyl)), alpha=0.8) +
#' labs(title="Density plot",
#' subtitle="City Mileage Grouped by Number of cylinders",
#' caption="Source: mpg",
#' x="City Mileage",
#' fill="# Cylinders") +
#' theme_terminator()
#'
theme_terminator <- function(terminator_font = TRUE, ...){
# CUSTOM FONT: add a custom font from google fonts
font_family = ifelse(terminator_font,"terminator","sans") # use this line if you have a custom font
if (terminator_font) {
initialize_font(name = "Orbitron", family = "terminator")
}
# CUSTOM THEME:
ggplot2::theme(
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
text = element_text(color = terminator_theme_colors["text"], family = font_family),
title = element_text(size=20),
panel.background = element_rect(fill = terminator_theme_colors["panel"]),
panel.border = element_rect(fill = NA, color = terminator_theme_colors["border"],linewidth=1.4),
axis.title = element_text(size=17),
axis.text = element_text(size=15,color = terminator_theme_colors["text"]),
axis.ticks = element_line(color = terminator_theme_colors["border"],linewidth=1),
legend.background = element_rect(fill = terminator_theme_colors["panel"], color = NA),
plot.background = element_rect(fill = terminator_theme_colors["panel"]),
strip.background = element_rect(fill = terminator_theme_colors["strip"], colour = terminator_theme_colors["border"]),
strip.text = element_text(colour = terminator_theme_colors["text"]),
...
)
}
# COLOR SCALES: Make pretty color scales
#' Terminator Inspired Color Scales
#'
#' @param ... Additional arguments to pass to `ggplot2::scale_[fill/color]_gradient()`
#'
#' @return a `ggplot` scale object
#'
#' @rdname scale_terminator
#' @export
#' @concept terminator
#'
#' @examples
#' library(ggplot2)
#'
#' ggplot(mpg) +
#' geom_point(aes(y = class, x = hwy, color = cyl)) +
#' labs(title="MPG by Vehicle Type",
#' caption="Source: mpg",
#' x = "City Mileage",
#' color ="# Cylinders") +
#' scale_color_terminator() +
#' theme_terminator(terminator_font = TRUE)
#'
scale_fill_terminator <- function(...) {
ggplot2::scale_fill_gradient(low = terminator_theme_colors["lighter"], high = terminator_theme_colors["dark"], ...)
}
#' @rdname scale_terminator
#' @export
#' @concept terminator
scale_color_terminator <- function(...) {
ggplot2::scale_color_gradient(low = terminator_theme_colors["lighter"], high = terminator_theme_colors["dark"], ...)
}