-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.qmd
72 lines (61 loc) · 1.76 KB
/
template.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
---
title: Template Title
subtitle: Subtitle
author: Lennart Klein
date: last-modified
format:
scl-html: default
execute:
cache: true
freeze: auto
warning: false
---
# Setup
```{r setup}
#| echo: true
#| output: false
library(tidyverse)
```
```{r theme}
#| eval: true
#| echo: false
scl_colors <- c("logo" = "#3653C8", "font" = "#243937", "#0B2E6E", "#0F4AB2")
theme_scl <- function(
base_size = 12,
base_family = "",
plot_title_size = 20,
plot_title_color = scl_colors["logo"]) {
ggplot2::theme_minimal(base_size = base_size, base_family = base_family) +
theme(
plot.background = element_rect(colour = "white"), # removed by minimal
text = element_text(color = "black"),
axis.text = element_text(color = "black"), # break labels
axis.title = element_text(color = "black", size = base_size), # axis labels
axis.line = element_line(),
legend.text = element_text(color = "black"),
plot.title = element_text(color = plot_title_color),
plot.caption = element_text(color = scl_colors["font"], size = 9, hjust = 0)
)
}
# theme_set(theme_grey()) # default
```
# Introduction
## Plot
- classic `ggplot2` example with custom `theme_scl()` function
- use `paletteer::scale_color_paletteer_d("colorblindr::OkabeIto_black")` for the Okabe-Ito (2008) colour-blind-friendly palette
```{r plot}
mpg %>%
ggplot(aes(x = displ, y = hwy)) +
geom_point(aes(color = class)) +
geom_smooth(color = scl_colors["logo"]) +
paletteer::scale_color_paletteer_d("colorblindr::OkabeIto_black") +
theme_scl() +
labs(
title = "Plot Example",
subtitle = "Plot Subtitle",
x = "Engine displacement",
y = "Highway miles per gallon",
color = "Class",
caption = "Data: EPA, Graphic: socialchangelab.org"
)
```