-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathREADME.qmd
320 lines (263 loc) · 10.5 KB
/
README.qmd
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
---
format: gfm
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges(
extra_lines = c(
"![downloads](https://cranlogs.r-pkg.org/badges/grand-total/hrbrthemes)",
"[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2545422.svg)](https://doi.org/10.5281/zenodo.2545422)"
)
)
```
## hrbrthemes
Additional Themes and Theme Components for 'ggplot2'
----
This is a very focused package that provides typography-centric themes and theme components for ggplot2.
The core theme: `theme_ipsum` ("ipsum" is Latin for "precise") uses Arial Narrow which should be installed on practically any modern system, so it's "free"-ish. This font is condensed, has solid default kerning pairs and geometric numbers. That's what I consider the "font trifecta" must-have for charts. An additional quality for fonts for charts is that they have a diversity of weights. Arial Narrow (the one on most systems, anyway) does not have said diversity but this quality is not (IMO) a "must have".
The following functions are implemented/objects are exported:
Themes:
- `theme_ipsum`: Arial Narrow
- `theme_ipsum_gs`: Goldman Sans Condensed
- `theme_ipsum_es`: Econ Sans Condensed
- `theme_ipsum_rc`: Roboto Condensed
- `theme_ipsum_ps`: IBM Plex Sans font
- `theme_ipsum_pub`: Public Sans
- `theme_ipsum_tw`: Titilium Web
- `theme_modern_rc`: Roboto Condensed dark theme
- `theme_ft_rc`: Dark theme based on FT's dark theme (Roboto Condensed)
Scales (that align with various themes):
- `scale_color_ipsum`: Discrete color & fill scales based on the ipsum palette
- `scale_colour_ipsum`: Discrete color & fill scales based on the ipsum palette
- `scale_fill_ipsum`: Discrete color & fill scales based on the ipsum palette
- `scale_color_ft`: Discrete color & fill scales based on the FT palette
- `scale_colour_ft`: Discrete color & fill scales based on the FT palette
- `scale_fill_ft`: Discrete color & fill scales based on the FT palette
- `scale_x_comma`: X & Y scales with opinionated presets for percent & comma label formats
- `scale_x_percent`: X & Y scales with opinionated presets for percent & comma label formats
- `scale_y_comma`: X & Y scales with opinionated presets for percent & comma label formats
- `scale_y_percent`: X & Y scales with opinionated presets for percent & comma label formats
Palettes/Named Colors:
- `ipsum_pal`: A muted, qualitative color palette
- `ft_cols`: FT color palette
- `ft_pal`: A bright qualitative color palette
- `ft_text_col`: FT color palette
Fonts:
- `font_an`: Arial Narrow font name R variable aliases
- `font_es`: Econ Sans font name R variable aliases
- `font_es_bold`: Econ Sans font name R variable aliases
- `font_es_light`: Econ Sans font name R variable aliases
- `font_rc`: Roboto Condensed font name R variable aliases
- `font_rc_light`: Roboto Condensed font name R variable aliases
- `font_pub`: Public Sans font name R variable aliases
- `font_pub_bold`: Public Sans font name R variable aliases
- `font_pub_light`: Public Sans font name R variable aliases
- `font_pub_thin`: Public Sans font name R variable aliases
- `font_ps`: PlexSans font name R variable aliases
- `font_ps_light`: PlexSans font name R variable aliases
Flexoki Color Scales:
- `scale_color_flexoki_light`: Discrete color scale using Flexoki light colors
- `scale_fill_flexoki_light`: Discrete fill scale using Flexoki light colors
- `scale_color_flexoki_dark`: Discrete color scale using Flexoki dark colors
- `scale_fill_flexoki_dark`: Discrete fill scale using Flexoki dark colors
- `scale_color_flexoki_continuous`: Continuous color scale with 8 palette options
- `scale_fill_flexoki_continuous`: Continuous fill scale with 8 palette options
Flexoki Palettes:
- `flexoki_light`: Vector of 8 colors in the light variant
- `flexoki_dark`: Vector of 8 colors in the dark variant
- `flexoki_extended`: List of 8 color palettes with 13 shades each for continuous interpolation
Utilities:
- `flush_ticks`: Makes axis text labels flush on the ends
- `ft_geom_defaults`: Change geom defaults from black to custom lights for the FT theme
- `gg_check`: Spell check ggplot2 plot labels
- `import_econ_sans`: Import Econ Sans Condensed font for use in charts
- `import_plex_sans`: Import IBM Plex Sans font for use in charts
- `import_roboto_condensed`: Import Roboto Condensed font for use in charts
- `modern_geom_defaults`: Change geom defaults from black to white for the modern theme
- `update_geom_font_defaults`: Update matching font defaults for text geoms
### Installation
```{r install-ex, results='asis', echo = FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
### Usage
```{r message=FALSE, warning=FALSE, error=FALSE}
library(hrbrthemes)
library(gcookbook)
library(tidyverse)
# current version
packageVersion("hrbrthemes")
```
### Base theme (Arial Narrow)
```{r an}
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
theme_ipsum()
```
### Roboto Condensed
```{r rc}
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
theme_ipsum_rc()
```
### New FT Theme!
```{r ft}
ggplot(mtcars, aes(mpg, wt)) +
geom_point(color = ft_cols$yellow) +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
theme_ft_rc()
```
### IBM Plex Sans
```{r ps, fig.width=10, fig.height=7}
ggplot(mpg, aes(displ, hwy)) +
geom_jitter(aes(color=class, fill=class), size=3, shape=21, alpha=1/2) +
scale_x_continuous(expand=c(0,0), limits=c(1, 8), breaks=1:8) +
scale_y_continuous(expand=c(0,0), limits=c(10, 50)) +
scale_color_ipsum() +
scale_fill_ipsum() +
facet_wrap(~class, scales="free") +
labs(
title="IBM Plex Sans Test",
subtitle="This is a subtitle to see the how it looks in IBM Plex Sans",
caption="Source: hrbrthemes & IBM"
) +
theme_ipsum_ps(grid="XY", axis="xy") +
theme(legend.position="none") -> gg
flush_ticks(gg)
```
### Scales (Color/Fill)
```{r sc}
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(color=factor(carb))) +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 scatterplot example",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
scale_color_ipsum() +
theme_ipsum_rc()
```
### Scales (Axis)
```{r ax1}
count(mpg, class) %>%
mutate(pct=n/sum(n)) %>%
ggplot(aes(class, pct)) +
geom_col() +
scale_y_percent() +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 column chart example with percents",
subtitle="A plot that is only useful for demonstration purposes",
caption="Brought to you by the letter 'g'") +
theme_ipsum(grid="Y")
```
```{r ax2, fig.height=6}
ggplot(uspopage, aes(x=Year, y=Thousands, fill=AgeGroup)) +
geom_area() +
scale_fill_ipsum() +
scale_x_continuous(expand=c(0,0)) +
scale_y_comma() +
labs(title="Age distribution of population in the U.S., 1900-2002",
subtitle="Example data from the R Graphics Cookbook",
caption="Source: R Graphics Cookbook") +
theme_ipsum_rc(grid="XY") +
theme(axis.text.x=element_text(hjust=c(0, 0.5, 0.5, 0.5, 1))) +
theme(legend.position="bottom")
```
```{r ax3}
update_geom_font_defaults(font_rc_light)
count(mpg, class) %>%
mutate(n=n*2000) %>%
arrange(n) %>%
mutate(class=factor(class, levels=class)) %>%
ggplot(aes(class, n)) +
geom_col() +
geom_text(aes(label=scales::comma(n)), hjust=0, nudge_y=2000) +
scale_y_comma(limits=c(0,150000)) +
coord_flip() +
labs(x="Fuel efficiency (mpg)", y="Weight (tons)",
title="Seminal ggplot2 column chart example with commas",
subtitle="A plot that is only useful for demonstration purposes, esp since you'd never\nreally want direct labels and axis labels",
caption="Brought to you by the letter 'g'") +
theme_ipsum_rc(grid="X")
```
### Spellcheck ggplot2 labels
```{r sp, message=TRUE}
df <- data.frame(x=c(20, 25, 30), y=c(4, 4, 4), txt=c("One", "Two", "Three"))
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
labs(x="This is some txt", y="This is more text",
title="Thisy is a titlle",
subtitle="This is a subtitley",
caption="This is a captien") +
theme_ipsum_rc(grid="XY") -> gg
gg_check(gg)
```
### Flexoki Color Scales
The Flexoki color system provides both discrete and continuous color scales in light and dark variants.
```{r flexoki1}
# Discrete colors example with light variant
ggplot(mpg, aes(class, fill=class)) +
geom_bar() +
labs(title="Flexoki Light Colors",
subtitle="Discrete color scale example",
caption="Using scale_fill_flexoki_light()") +
theme_ipsum() +
scale_fill_flexoki_light() +
theme(legend.position="none")
```
```{r flexoki2}
# Dark variant with points
ggplot(mpg, aes(displ, hwy, color=class)) +
geom_point(size=3) +
labs(title="Flexoki Dark Colors",
subtitle="Another discrete color example",
caption="Using scale_color_flexoki_dark()") +
theme_ipsum_rc() +
scale_color_flexoki_dark()
```
```{r flexoki-03, fig.width=10, fig.height=6}
library(patchwork)
data.frame(
x = rep(1:50, 50),
y = rep(1:50, each=50),
z = sqrt((rep(1:50, 50)-25)^2 + (rep(1:50, each=50)-25)^2)
) -> grad_df
names(flexoki_dark) |>
map(\(.p) {
ggplot(grad_df, aes(x, y, fill=z)) +
geom_tile() +
scale_fill_flexoki_continuous(palette = .p) +
labs(
x = NULL, y = NULL
) +
theme_ipsum(grid="") +
theme(legend.position = "none")
}) |>
do.call(what = "wrap_plots") +
plot_layout(ncol = 4) +
plot_annotation(
title="Flexoki Continuous Color Scales",
subtitle="All 8 continuous color palettes",
caption="Using scale_fill_flexoki_continuous()",
theme = theme_ipsum(grid="")
)
```
### hrbrthemes Metrics
```{r cloc, echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
cloc::cloc_pkg_md()
```
### Code of Conduct
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.