-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbook-functions.R
60 lines (53 loc) · 1.93 KB
/
book-functions.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
style_data <- function(dat, n_rows = NULL, caption = NULL) {
if (is.null(n_rows)) {
if (nrow(dat) < 10) {
n_rows <- nrow(dat)
} else {
n_rows <- 10
}
}
dat[1:n_rows,] |>
knitr::kable(caption = caption) |>
kableExtra::kable_styling(
bootstrap_options = c("striped", "hover", "condensed", "responsive"),
fixed_thead = TRUE
)
}
### preloading font packages
library(showtext)
library(extrafont)
library(ggtext)
### adding roboto font from file and then loading
font_add(family = "Roboto", regular = "C:/Windows/Fonts/RobotoCondensed-Regular.ttf")
extrafont::loadfonts(quiet = TRUE)
### setting options for chunks in output
knitr::opts_chunk$set(warning = FALSE, message = FALSE, error = FALSE, fig.showtext = TRUE,
cache = TRUE, out.width = "95%", out.height = "95%")
options(
pillar.max_footer_lines = 2,
pillar.bold = TRUE,
width = 70)
### creating theme used in ggplot
nfl_analytics_theme <- function(..., base_size = 12) {
theme(
text = element_text(family = "Roboto", size = base_size, color = "black"),
axis.ticks = element_blank(),
axis.title = element_text(face = "bold"),
axis.text = element_text(face = "bold"),
plot.title.position = "plot",
plot.title = element_markdown(size = 16,
vjust = .02,
hjust = 0.5),
plot.subtitle = element_markdown(hjust = 0.5),
plot.caption = element_markdown(size = 8),
panel.grid.minor = element_blank(),
panel.grid.major = element_line(color = "#d0d0d0"),
panel.background = element_rect(fill = "#f7f7f7"),
plot.background = element_rect(fill = "#f7f7f7"),
panel.border = element_blank(),
legend.background = element_rect(color = "#F7F7F7"),
legend.key = element_rect(color = "#F7F7F7"),
legend.title = element_text(face = "bold"),
legend.title.align = 0.5,
strip.text = element_text(face = "bold"))
}