1
+ # '
2
+ # ' GNC colours
3
+ # '
4
+ # ' @examples
5
+ # ' gnc_green
6
+ # ' gnc_grey
7
+ # ' gnc_sage
8
+ # '
9
+ # ' @rdname gnc_colours
10
+ # ' @export
11
+ # '
12
+ gnc_green <- " #9CCB38"
13
+
14
+ # '
15
+ # ' @rdname gnc_colours
16
+ # ' @export
17
+ # '
18
+ gnc_grey <- " #808080"
19
+
20
+ # '
21
+ # ' @rdname gnc_colours
22
+ # ' @export
23
+ # '
24
+ gnc_sage <- " #94A17F"
25
+
26
+ # '
27
+ # ' @rdname gnc_colours
28
+ # ' @export
29
+ # '
30
+ gnc_dark_green <- " #63A537"
31
+
32
+ # '
33
+ # ' @rdname gnc_colours
34
+ # ' @export
35
+ # '
36
+ gnc_lime <- " #37A76F"
37
+
38
+ # '
39
+ # ' @rdname gnc_colours
40
+ # ' @export
41
+ # '
42
+ gnc_aqua_green <- " #44C1A3"
43
+
44
+ # '
45
+ # ' @rdname gnc_colours
46
+ # ' @export
47
+ # '
48
+ gnc_cyan <- " #4Eb3CF"
49
+
50
+ # '
51
+ # ' @rdname gnc_colours
52
+ # ' @export
53
+ # '
54
+ gnc_blue <- " #51C3F9"
55
+
56
+ # '
57
+ # ' @rdname gnc_colours
58
+ # ' @export
59
+ # '
60
+ gnc_orange <- " #EE7B08"
61
+
62
+ # '
63
+ # ' @rdname gnc_colours
64
+ # ' @export
65
+ # '
66
+ gnc_moss_green <- " #455F51"
67
+
68
+ # '
69
+ # ' @rdname gnc_colours
70
+ # ' @export
71
+ # '
72
+ gnc_gold <- " #89824E"
73
+
74
+
75
+ # '
76
+ # ' GNC palettes
77
+ # '
78
+ # ' @examples
79
+ # ' gnc_palettes
80
+ # '
81
+ # ' @rdname gnc_palette
82
+ # ' @export
83
+ # '
84
+ gnc_palettes <- list (
85
+ gnc_primary = gnc_green ,
86
+ gnc_secondary = c(
87
+ gnc_grey , gnc_sage , gnc_dark_green , gnc_lime , gnc_aqua_green , gnc_cyan ,
88
+ gnc_blue , gnc_orange , gnc_moss_green , gnc_gold
89
+ ),
90
+ gnc_greens = c(
91
+ " #F5F9EB" , " #EBF4D7" , " #E1EFC3" , " #D7EAAF" , " #CDE59B" ,
92
+ " #C3DF87" , " #B9DA73" , " #AFD55F" , " #A5D04B" , " #9CCB38"
93
+ ),
94
+ gnc_greys = c(
95
+ " #F2F2F2" , " #E5E5E5" , " #D8D8D8" , " #CCCCCC" , " #BFBFBF" ,
96
+ " #B2B2B2" , " #A6A6A6" , " #999999" , " #8C8C8C" , " #808080"
97
+ ),
98
+ gnc_sages = c(
99
+ " #F4F5F2" , " #E9ECE5" , " #DEE2D8" , " #D4D9CB" , " #C9D0BF" ,
100
+ " #BEC6B2" , " #B4BDA5" , " #A9B398" , " #9EAA8B" , " #94A17F"
101
+ ),
102
+ gnc_dark_greens = c(
103
+ " #DFEDD7" , " #C0DBAF" , " #A1C987" , " #82B75F" , " #63A537"
104
+ ),
105
+ gnc_limes = c(
106
+ " #D7EDE2" , " #AFDBC5" , " #87CAA8" , " #5FB88B" , " #37A76F"
107
+ ),
108
+ gnc_aqua_greens = c(
109
+ " #D9F2EC" , " #B4E6DA" , " #8ED9C7" , " #69CDB5" , " #44C1A3"
110
+ ),
111
+ gnc_cyans = c(
112
+ " #DBEFF5" , " #B8E0EB" , " #94D1E2" , " #71C2D8" , " #4EB3CF"
113
+ ),
114
+ gnc_blues = c(
115
+ " #DCF3FD" , " #B9E7FC" , " #96DBFB" , " #73CFFA" , " #51C3F9"
116
+ ),
117
+ gnc_oranges = c(
118
+ " #FBE4CD" , " #F8CA9C" , " #F4AF6A" , " #F19539" , " #EE7B08"
119
+ ),
120
+ gnc_moss_greens = c(
121
+ " #D9DFDC" , " #B4BFB9" , " #8F9F96" , " #6A7F73" , " #455F51"
122
+ ),
123
+ gnc_golds = c(
124
+ " #E7E6DB" , " #CFCDB8" , " #B8B494" , " #A09B71" , " #89824E"
125
+ )
126
+ )
127
+
128
+
129
+ # '
130
+ # ' GNC fonts
131
+ # '
132
+ # ' @examples
133
+ # ' gnc_fonts
134
+ # '
135
+ # ' @rdname gnc_font
136
+ # ' @export
137
+ # '
138
+
139
+ gnc_fonts <- list (
140
+ gnc_arial = " Arial" ,
141
+ gnc_calibri = " Calibri Regular" ,
142
+ acdc_source_sans_pro = " Source Sans Pro" ,
143
+ acdc_bebas_neue = " Bebas Neue"
144
+ )
145
+
146
+
147
+ # '
148
+ # ' Set GNC font to use based on what is available from the system
149
+ # '
150
+ # ' The function will search the system for availability of any of the GNC fonts
151
+ # ' in hierarchical order starting with *Arial*, then *Calibri Regular*, then
152
+ # ' *Source Sans Pro*, and then finally *Arial*. If none of these are found in
153
+ # ' the system, the function will return *Noto Sans* by default or the user can
154
+ # ' set which font to use as alternative by specifying `alt`.
155
+ # '
156
+ # ' @param alt A character value for font family to use if all of the GNC fonts
157
+ # ' are not available in the system.
158
+ # '
159
+ # ' @returns A character value for font family to use as GNC font.
160
+ # '
161
+ # ' @examples
162
+ # ' set_gnc_font()
163
+ # '
164
+ # ' @rdname gnc_font
165
+ # ' @export
166
+ # '
167
+
168
+ set_gnc_font <- function (alt = paleta_fonts $ paleta_noto ) {
169
+ # # Detect which fonts are available to the system ----
170
+ fonts <- systemfonts :: system_fonts()
171
+
172
+ # # Check which GNC font is available ----
173
+ if (any(fonts $ family == gnc_fonts $ gnc_arial )) {
174
+ gnc_font <- gnc_fonts $ gnc_arial
175
+ } else {
176
+ if (any(fonts $ family == gnc_fonts $ gnc_calibri )) {
177
+ gnc_font <- gnc_fonts $ gnc_calibri
178
+ } else {
179
+ if (any(fonts $ family == gnc_fonts $ gnc_source_sans_pro )) {
180
+ gnc_font <- gnc_fonts $ gnc_source_sans_pro
181
+ } else {
182
+ if (any(fonts $ family == gnc_fonts $ gnc_bebas_neue )) {
183
+ gnc_font <- gnc_fonts $ gnc_bebas_neue
184
+ } else {
185
+ gnc_font <- alt
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ # # Return gnc_font ----
192
+ gnc_font
193
+ }
194
+
195
+
196
+ # '
197
+ # ' A [ggplot2] theme using GNC fonts, colours, and palettes
198
+ # '
199
+ # ' These are wrappers for [theme_paleta()] that use colours and fonts from the
200
+ # ' GNC visual identity guidelines.
201
+ # '
202
+ # ' @section Colours:
203
+ # ' The GNC theme is based on the colours from the [gnc_palettes]. The
204
+ # ' primary palette consists of one colour: `gnc_palettes$gnc_primary`.
205
+ # ' The secondary palette consists of ten colours:
206
+ # ' `gnc_palettes$gnc_secondary`.
207
+ # '
208
+ # ' @section Fonts:
209
+ # ' The GNC theme uses four fonts as prescribed by the GNC visual identity
210
+ # ' guidelines. These fonts (in hierarchical order of preference) are
211
+ # ' *Arial*, *Calibri*, *Source Sans Pro*, and *Bebas Neue*. Any or all of these
212
+ # ' fonts should be available in the user's system for them to be used in the
213
+ # ' theme. If none of these fonts are available in the user's system, a freely
214
+ # ' downloadable alternative called *Noto Sans* is the default fallback font and
215
+ # ' can be obtained from [Google Fonts](https://fonts.google.com/).
216
+ # '
217
+ # ' @param base_family Base font family using GNC fonts. Default is set
218
+ # ' by what GNC font is available in the system via [set_gnc_font()].
219
+ # ' If none of the GNC fonts are available, the default becomes
220
+ # ' *Noto Sans*.
221
+ # ' @param base_size Base font size. Default is 11.5.
222
+ # ' @param plot_title_family Font family to use for the plot title. Default is
223
+ # ' `base_family`.
224
+ # ' @param plot_title_colour Colour of the plot title text. Default
225
+ # ' is [gnc_grey].
226
+ # ' @param subtitle_family Font family to use for the plot subtitle. Default is
227
+ # ' `base_family`.
228
+ # ' @param subtitle_colour Colour of the subtitle text. Default is
229
+ # ' [gnc_grey].
230
+ # ' @param caption_colour Colour of the caption text. Default is
231
+ # ' [gnc_grey].
232
+ # ' @param axis_title_colour Colour of the axis title text. Default is
233
+ # ' [gnc_grey].
234
+ # ' @param legend_title_colour Colour of the legend title text. Default is NULL.
235
+ # ' @param legend_text_colour Colour of the legend text. Default is NULL.
236
+ # ' @param grid_col Grid colour. Default to [gnc_grey].
237
+ # ' @param axis_col Axis colours. Default to [gnc_grey].
238
+ # ' @param grid Panel grid. Either `TRUE`, `FALSE`, or a combination of
239
+ # ' `X` (major x grid), `x` (minor x grid), `Y` (major y grid), and/or
240
+ # ' `y` (minor y grid). Default is TRUE.
241
+ # ' @param axis Add x or y axes? `TRUE`, `FALSE`, "`xy`". Default is FALSE.
242
+ # ' @param ticks Logical. Should ticks be added? Default is FALSE.
243
+ # '
244
+ # ' @returns A [ggplot2] theme.
245
+ # '
246
+ # ' @examples
247
+ # ' \dontrun{
248
+ # ' ggplot(
249
+ # ' data = mtcars,
250
+ # ' mapping = aes(
251
+ # ' x = factor(vs, levels = c(0, 1), labels = c("v-shaped", "straight")),
252
+ # ' fill = factor(cyl))
253
+ # ' ) +
254
+ # ' geom_bar() +
255
+ # ' scale_fill_manual(
256
+ # ' name = "Cylinders",
257
+ # ' values = gnc_palettes$gnc_secondary
258
+ # ' ) +
259
+ # ' labs(
260
+ # ' title = "Engine shape by number of cylinders",
261
+ # ' subtitle = "An example plot for this package",
262
+ # ' x = "Engine Shape",
263
+ # ' y = "Counts"
264
+ # ' ) +
265
+ # ' theme_unicef()
266
+ # ' }
267
+ # '
268
+ # ' @rdname theme_unicef
269
+ # ' @export
270
+ # '
271
+ theme_gnc <- function (base_family = set_gnc_font(),
272
+ base_size = 11.5 ,
273
+ plot_title_family = base_family ,
274
+ plot_title_colour = gnc_grey ,
275
+ subtitle_family = base_family ,
276
+ subtitle_colour = gnc_grey ,
277
+ caption_colour = gnc_grey ,
278
+ axis_title_colour = gnc_grey ,
279
+ legend_title_colour = gnc_grey ,
280
+ legend_text_colour = gnc_grey ,
281
+ grid_col = gnc_grey ,
282
+ grid = TRUE ,
283
+ axis_col = gnc_grey ,
284
+ axis = FALSE ,
285
+ ticks = FALSE ) {
286
+ theme_paleta(
287
+ base_family = base_family ,
288
+ base_size = base_size ,
289
+ plot_title_family = plot_title_family ,
290
+ plot_title_colour = plot_title_colour ,
291
+ subtitle_family = subtitle_family ,
292
+ subtitle_colour = subtitle_colour ,
293
+ caption_colour = caption_colour ,
294
+ axis_title_colour = axis_title_colour ,
295
+ legend_title_colour = legend_title_colour ,
296
+ legend_text_colour = legend_text_colour ,
297
+ grid_col = grid_col ,
298
+ grid = grid ,
299
+ axis_col = axis_col ,
300
+ axis = axis ,
301
+ ticks = ticks
302
+ )
303
+ }
0 commit comments