-
Notifications
You must be signed in to change notification settings - Fork 13
/
theme_zelda.R
125 lines (115 loc) · 3.64 KB
/
theme_zelda.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
118
119
120
121
122
123
124
125
## Alex Slavenko
## theme_zelda
## 25/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
#' Legend of Zelda Theme Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept zelda
#'
#' @examples
#' zelda_theme_colors
#'
zelda_theme_colors <- c(
text = '#1F4C73',
panel = '#F2EED8',
border = '#FBF6E2',
lighter = '#C4F9F3',
light = '#65D6B8',
medium = '#3C92A6',
dark = '#1F4C73'
)
#' Legend of Zelda Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept zelda
#'
#' @examples
#' zelda_palette
#'
zelda_palette <- c('#494b4b', '#0e5135','#0d9263','#4aba91','#d4ce46')
# THEME: rename function and theme() arguments according to your theme design, feel free to edit this how you would like
#' Legend of Zelda Inspired Theme
#'
#' @param zelda_font should `theme_zelda` 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 zelda
#'
#' @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() +
#' labs(title = 'Zelda Scatter Plot') +
#' theme_zelda()
#'
#' 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_zelda()
#'
theme_zelda <- function(zelda_font = TRUE, ...){
# CUSTOM FONT: add a custom font from google fonts
font_family = ifelse(zelda_font,"zelda","sans") # use this line if you have a custom font
if (zelda_font) {
initialize_font(name = "Spectral SC", family = "zelda")
}
# CUSTOM THEME:
ggplot2::theme(
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
text = element_text(color = zelda_theme_colors["text"], family = font_family),
title = element_text(size=20),
panel.background = element_rect(fill = zelda_theme_colors["panel"]),
panel.border = element_rect(fill = NA, color = zelda_theme_colors["border"],linewidth=1.2),
axis.title = element_text(size=17),
axis.text = element_text(size=13),
axis.ticks = element_line(color = zelda_theme_colors["border"],linewidth=1),
legend.background = element_rect(fill = zelda_theme_colors["panel"], color = NA),
strip.background = element_rect(fill = zelda_theme_colors["lighter"], colour = zelda_theme_colors["border"]),
strip.text = element_text(colour = zelda_theme_colors["text"]),
...
)
}
# COLOR SCALES: Make pretty color scales
#' Legend of Zelda Inspired Color Scales
#'
#' @param ... Additional arguments to pass to `ggplot2::scale_[fill/color]_gradient()`
#'
#' @return a `ggplot` scale object
#'
#' @rdname scale_zelda
#' @export
#' @concept zelda
#'
#' @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_zelda() +
#' theme_zelda(zelda_font = TRUE)
#'
scale_fill_zelda <- function(...) {
ggplot2::scale_fill_gradient(low = zelda_theme_colors["lighter"], high = zelda_theme_colors["dark"], ...)
}
#' @rdname scale_zelda
#' @export
#' @concept zelda
scale_color_zelda <- function(...) {
ggplot2::scale_color_gradient(low = zelda_theme_colors["lighter"], high = zelda_theme_colors["dark"], ...)
}