-
Notifications
You must be signed in to change notification settings - Fork 18
/
before-chapter.R
97 lines (83 loc) · 2.93 KB
/
before-chapter.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
95
96
97
# LIBRARY CONFIGURATION
library(ggplot2)
library(grid)
library(gridExtra)
library(knitr)
knitr::opts_chunk$set(
include = TRUE,
cache = TRUE,
collapse = TRUE,
echo = FALSE,
message = FALSE,
tidy = FALSE,
warning = FALSE,
comment = " ",
dev = "png",
dev.args = list(bg = '#FFFFF8'),
dpi = 300,
fig.align = "center",
fig.width = 7,
fig.asp = 0.618,
fig.show = "hold",
out.width = "90%"
)
library(tufte)
# UTILITY FUNCTIONS
printf <- function(pattern, ...) {
cat(sprintf(pattern, ...))
}
print_file <- function(file) {
cat(paste(readLines(file), "\n", sep=""), sep="")
}
extract_one_draw <- function(stanfit, chain = 1, iter = 1) {
x <- get_inits(stanfit, iter = iter)
x[[chain]]
}
# TUFTE GGPLOT STYLE
ggtheme_tufte <- function() {
theme(plot.background =
element_rect(fill = "#fffff8",
colour = "#fffff8",
size = 0.5,
linetype = "solid"),
plot.margin=unit(c(1, 1, 0.5, 0.5), "lines"),
panel.background =
element_rect(fill = "#fffff8",
colour = "#fffff8",
size = 0.5,
linetype = "solid"),
panel.grid.major = element_line(colour = "white",
size = 1, linetype="dashed"),
panel.grid.minor = element_blank(),
legend.box.background =
element_rect(fill = "#fffff8",
colour = "#fffff8",
linetype = "solid"),
axis.line = element_blank(),
axis.ticks = element_blank(),
axis.text = element_text(family = "Palatino", size = 12),
axis.title.x = element_text(family = "Palatino", size = 14,
margin = margin(t = 15,
r = 0, b = 0, l = 0)),
axis.title.y = element_text(family = "Palatino", size = 14,
margin = margin(t = 0,
r = 15, b = 0, l = 0)),
strip.background = element_rect(fill = "#fffff8",
colour = "#fffff8",
linetype = "solid"),
strip.text = element_text(family = "Palatino", size = 12),
legend.text = element_text(family = "Palatino", size = 12),
legend.title = element_text(family = "Palatino", size = 14,
margin = margin(b = 5)),
legend.background = element_rect(fill = "#fffff8",
colour = "#fffff8",
linetype = "solid"),
legend.key = element_rect(fill = "#fffff8",
colour = "#fffff8",
linetype = "solid")
)
}
# GENERAL R CONFIGURATION
options(digits = 2)
options(htmltools.dir.version = FALSE)
set.seed(1123)