-
Notifications
You must be signed in to change notification settings - Fork 13
/
theme_lordoftherings.R
122 lines (112 loc) · 3.71 KB
/
theme_lordoftherings.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
## Ethan Milne
## theme_lordoftherings
## 24/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
#' Lord of the Rings Theme Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept lordoftherings
#'
#' @examples
#' lordoftherings_theme_colors
#'
lordoftherings_theme_colors <- c(
text = '#020203',
panel = '#e0dcce',
border = '#ab8d59',
lighter = '#6bb49e',
light = '#89b498',
medium = '#559468',
dark = '#34684f'
)
#' Sauron Color Palette
#'
#' @format character vector of hex code strings
#' @export
#' @concept lordoftherings
#'
#' @examples
#' sauron_palette
#'
sauron_palette <- c('#fcd882', '#e8a578','#df7b75','#4e2828','#180109')
# THEME: rename function and theme() arguments according to your theme design, feel free to edit this how you would like
#' Lord of the Rings Inspired Theme
#'
#' @param lordoftherings_font should `theme_lordoftherings` use Google Font's Lugrasimo? Default is `TRUE`.
#' @param ... additional parameters to pass to `ggplot2::theme()`
#'
#' @return a `ggplot2` `theme` element
#' @export
#' @concept lordoftherings
#'
#' @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 = 'Lord of the Rings Scatter Plot') +
#' theme_lordoftherings()
#'
#' 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_lordoftherings()
#'
theme_lordoftherings <- function(lordoftherings_font = TRUE, ...){
# CUSTOM FONT: add a custom font from google fonts
font_family = ifelse(lordoftherings_font,"lordoftherings","sans") # use this line if you have a custom font
if (lordoftherings_font) {
initialize_font(name = "MedievalSharp", family = "lordoftherings")
}
# CUSTOM THEME:
ggplot2::theme(
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
text = element_text(color = lordoftherings_theme_colors["text"], family = font_family),
title = element_text(size=20),
panel.background = element_rect(fill = lordoftherings_theme_colors["panel"]),
panel.border = element_rect(fill = NA, color = lordoftherings_theme_colors["border"], linewidth = 2),
axis.title = element_text(size=17),
axis.text = element_text(size=13),
axis.ticks = element_line(color = lordoftherings_theme_colors["border"], linewidth = 1.2),
legend.background = element_rect(fill = lordoftherings_theme_colors["panel"], color = NA),
...
)
}
# COLOR SCALES: Make pretty color scales
#' Lord of the Rings Inspired Color Scales
#'
#' @param ... Additional arguments to pass to `ggplot2::scale_[fill/color]_gradient()`
#'
#' @return a `ggplot` scale object
#'
#' @rdname scale_lordoftherings
#' @export
#' @concept lordoftherings
#'
#' @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_lordoftherings()
#'
scale_fill_lordoftherings <- function(...) {
ggplot2::scale_fill_gradient(low = lordoftherings_theme_colors["lighter"], high = lordoftherings_theme_colors["dark"], ...)
}
#' @rdname scale_lordoftherings
#' @export
#' @concept lordoftherings
scale_color_lordoftherings <- function(...) {
ggplot2::scale_color_gradient(low = lordoftherings_theme_colors["lighter"], high = lordoftherings_theme_colors["dark"], ...)
}