-
Notifications
You must be signed in to change notification settings - Fork 1
/
ki.R
94 lines (88 loc) · 3.49 KB
/
ki.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
ki_color_palette_labelled <- c("Mörk plommon" = "#4F0433",
"Orange" = "#FF876F",
"Ljusorange" = "#FEEEEB",
"Ljusblå" = "#EDF4F4",
"Plommon (logotypfärg)" = "#870052",
"Mörk orange" = "#B84145",
"Mörkblå" = "#002C34",
"Blå" = "#4DB5BC")
ki_color_palette <- c("#4F0433",
"#FF876F",
"#870052",
"#B84145",
"#002C34",
"#4DB5BC",
"#FEEEEB",
"#EDF4F4")
# DM Sans
library(showtext)
## Load Google fonts from the web (https://fonts.google.com/)
#font_add_google("DM Sans")
## Load downloaded Google font to avoid dependence on internet access
font_add("DM Sans", "materials/DM_Sans/DMSans-Regular.ttf",
bold = "materials/DM_Sans/DMSans-Bold.ttf",
italic = "materials/DM_Sans/DMSans-Italic.ttf")
## Automatically use showtext to render text
showtext_auto()
theme_ki <- function(fontfamily = "DM Sans", axisSize = 13, titleSize = 15, subtitleSize = 12,
margins = 12, axisFace = "plain", stripSize = 11,
panelDist = 0.6, legendSize = 11, legendTsize = 11) {
theme_minimal() +
theme(
text = element_text(family = fontfamily),
plot.title = element_text(
family = fontfamily,
size = titleSize,
),
plot.subtitle = element_text(
family = fontfamily,
size = subtitleSize,
face = "bold"
),
axis.title.x = element_text(
margin = margin(t = margins),
size = axisSize
),
axis.title.y = element_text(
margin = margin(r = margins),
size = axisSize
),
axis.title = element_text(
face = axisFace
),
plot.caption = element_text(
face = "italic"
),
legend.text = element_text(family = fontfamily,
size = legendSize),
legend.title = element_text(family = fontfamily,
size = legendTsize),
strip.text = element_text(size = stripSize),
legend.background = element_rect(color = "lightgrey"),
strip.background = element_rect(color = "lightgrey"),
panel.spacing = unit(panelDist, "cm", data = NULL),
panel.border = element_rect(color = "grey", fill = NA)
)
}
### Add this line to a ggplot to get KI color and fill:
# + scale_color_manual(aesthetics = c("fill","color"), values = ki_color_palette)
### These rows are optional for changing fonts for geom_text() and geom_text_repel(),
### etc, to match font family if needed.
### add to ggplot object with "+"
# update_geom_defaults("text", list(family = fontfamily)) +
# update_geom_defaults("text_repel", list(family = fontfamily)) +
# update_geom_defaults("textpath", list(family = fontfamily)) +
# update_geom_defaults("texthline", list(family = fontfamily))
kbl_ki <- function(data, width = 75, fontsize = 14) {
kbl(data, booktabs = T, escape = F, table.attr = glue("style='width:{width}%;'")) %>%
kable_styling(
bootstrap_options = c("striped", "hover"),
position = "left",
full_width = T,
font_size = fontsize,
fixed_thead = T,
latex_options = c("striped", "scale_down")
) %>%
row_spec(0, bold = T) %>%
kable_classic(html_font = "Arial")
}