-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
434 lines (278 loc) · 8.37 KB
/
index.Rmd
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
---
title: "<br> RMeetup"
subtitle: "Mastering Corporate Design with R"
author: "Thomas Lo Russo, Andrea Schnell<br> 7. November 2017"
output:
xaringan::moon_reader:
css: libs/testzh.css
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
self_contained: false
---
class: inverse, center, middle
# The state of corporate design @ STAT ZH
---
class: middle, left
#The state of CD @ <font color=#009ee0>STAT ZH</font>
- Generic CD Guidelines for cantonal public administration cover the basics (e.g. fonts)
- No centralized publishing, several self-publishers
- Infographics (Website & Twitter), Excel-Tables, statistik.info
- professionaly layouted publications are the exception
- How do we achieve <b>visual uniformity</b> of our products?
--
- <b>'Do it yourself' Corporate Design Toolbox</b>
---
class: middle, left
# Corporate-Design Toolbox
- Colors for R-graphics <font color=#009ee0>zhpal</font>
- Write data in formated Excel-Tables <font color=#009ee0>statXLSX</font>
- Theme for ggplot2 graphics <font color=#009ee0>theme_stat</font>
- Reports & pdf documents <font color=#009ee0>statRmd</font>
---
class: inverse, center, middle
# ZH Color Palette
---
class: center, middle
Not the ideal <font color=#009ee0>color-palette</font> for graphs.
```{r tidy=FALSE,echo=FALSE}
library(scales)
library(ggplot2)
library(statR)
ggplot(diamonds, aes(clarity, fill=clarity))+
geom_bar(position = "stack", width = 1)+
scale_fill_manual(values=zhpal$zhcd)
```
---
### How we created our own color-scheme
- **Color palette creation** with R
- Mute the cd colors (color interpolation)
- Adapt the color space (LAB instead of RGB)
- Creation of a color-matrix (varying hue AND saturation)
- Testing for Colorblind-friendliness
<font color=#009ee0>Resources:</font>
**Interpolation** → grDevices::colorRampPalette()
**Colorblind-Testing** → Dichromat-package
---
class: center,middle
```{r tidy=FALSE,echo=FALSE}
library(statR)
library(scales)
show_col(c(zhpal$zhdarker,zhpal$zhdark,zhpal$zh,zhpal$zhlight,zhpal$zhpastel,zhpal$zhextralight,zhpal$zhultralight), borders=FALSE)
```
---
class: center,middle
.pull-left[
```{r tidy=FALSE,echo=TRUE}
p = ggplot(diamonds, aes(clarity, fill=cut)) +
geom_bar(position = "stack", width= 0.5)
p +theme_stat() +
scale_fill_manual(values=zhpal$zhdiagonal)
```
]
.pull-right[
```{r tidy=FALSE,echo=TRUE}
library(dichromat)
p +theme_stat() +
scale_fill_manual(values=dichromat(zhpal$zhdiagonal,type=c("tritan")))
```
]
---
background-image: url(libs/darthvader.jpg)
background-position: 50% 50%
class: center, bottom, inverse
---
class: inverse, center, middle
# Producing already formated XLSX-tables with R
---
background-image: url(libs/turtles.gif)
background-position: 50% 10%
background-size: 80%
class: center, bottom, inverse
## Our users love Excel-tables
100+ Excel-tables on our website<br>
Data is delivered in Excel-tables to users on a daily-basis<br>
No strict guidelines on how XLSX files should look like
.footnote[[<font color=#FFFFFF>Gif: Hoguemr, reddit<font>](https://www.reddit.com/r/funny/comments/1gzksk/work_was_a_little_slow_for_me_this_morning_again/)]
---
background-image: url(libs/excel.gif)
background-size: contain
class: center, bottom
---
#statXLSX
Creating formated excel-tables straight-out-of-R saves time and reduces the risk of errors. We recurred to the [***openxlsx-package***](https://cran.r-project.org/web/packages/openxlsx/openxlsx.pdf) package to define functions that write R-datasets in formated STAT ZH-Excel-tables.
***single worksheet***
statR::quickXLSX(data,"name of the table")
***multiple worksheets***
statR::statXLSX(data,"name of the table", worksheets)
***Advantages***
+End-to-end reproducibility
+quality assurance, less error prone
+visual coherence
---
background-image: url("libs/5.PNG")
background-size: contain
class: center, bottom
---
background-image: url("libs/6.PNG")
background-size: contain
class: center, bottom
---
class: inverse, center, bottom
# theme_stat()
## <br>a theme for ggplot2 graphics
<br>
.right[
<IMG SRC="http://hexb.in/hexagons/ggplot2.png" width = "150" height = auto>]
---
class:top, left
# Graphics with <font color=#009ee0>theme_stat()</font>
```{r, eval = T, echo = F, include = F}
library(ggplot2)
library(statRmd)
library(dplyr)
library(formatR)
library(gridExtra)
source("L:/STAT/03_AS/01_Werkzeuge/01_Toolbox/R/Funktionen/theme_stat_tex.r")
source("L:/STAT/03_AS/01_Werkzeuge/01_Toolbox/R/Funktionen/theme_stat.r")
```
.pull-left[
```{r, eval = F, echo = T, fig.height=5, fig.width=7, fig.align='center'}
ggplot(mtcars,
aes(x = factor(cyl),
fill = factor(cyl)))+
geom_bar()
```
<br>
```{r, eval = T, echo = F, fig.height=4.55, fig.width=5, fig.align='center'}
ggplot(mtcars,
aes(x = factor(cyl),
fill = factor(cyl)))+
geom_bar()
```
]
--
.pull-right[
```{r, eval = F, echo = T, tidy=T, tidy.opts=list(blank=FALSE, width.cutoff=30)}
ggplot(mtcars,
aes(x = factor(cyl),
fill = factor(cyl)))+
geom_bar()+
*theme_stat()
```
```{r, eval = T, echo = F, fig.height=4.5, fig.width=5, fig.align='center'}
ggplot(mtcars, aes(x = factor(cyl),
fill = factor(cyl)))+
geom_bar()+
theme_stat()+
scale_fill_manual(values = zhpal$zhbygseq, name = NULL)+
labs(y = NULL, x = NULL)
```
]
---
class: inverse, center, bottom
# statRmd
## <br>RMarkdown pdf templates
<br>
.right[
<IMG SRC="http://hexb.in/hexagons/rstudio.png" width = "150" height = auto><IMG SRC="http://hexb.in/hexagons/rmarkdown.png" width = "150" height = auto><IMG SRC="http://hexb.in/hexagons/knitr.png" width = "150" height = auto>]
---
class: left, top
# Our Analytical Publications
### PDF publications (mainly online)
.pull-left[
[<b> statistik.info</b>](https://statistik.zh.ch/internet/justiz_inneres/statistik/de/themen/statistikinfo.html)
- custom made
- stand-alone
- single-authored projects
- text-intensive
.center[<IMG SRC=libs/info.gif width = "150" height = auto>]
]
.pull-right[
<font color=#009ee0><b>Periodic reports</b></font>
- highly automated
- parameterized
- «reproducible»
- mainly charts and tables
.center[<IMG SRC=libs/report.gif width = "150" height = auto>]
]
---
class: top, left
# Workflow
### Current state
- Analysis in various .r files
- Produce graphics with R and save as .png
- Include .png in Word template
- Publish Word as PDF
--
### Goal
Establish an analysis and publication process, that is
- traceable
- «reproducible»
- allows publication of high quality charts and maps
- in accordance to our corporate design
--
.large[<font color=#009ee0>➡ RMarkdown</font>]
---
class: left, top
# RMarkdown pdf output
.pull-left[
### Default
```{r, eval = F, echo = T, tidy=T, tidy.opts=list(blank=FALSE, width.cutoff=30)}
---
title: "Title"
author: "Name"
output:
* pdf_document
---
```
.center[<IMG SRC=libs/RMarkdown_default.PNG width = "150" height = auto>]
]
--
.pull-right[
###statRmd::stat_report
```{r, eval = F, echo = T, tidy=T, tidy.opts=list(blank=FALSE, width.cutoff=30)}
---
title: "Haupttitel"
author: "Vorname Nachname"
output:
* statRmd::stat_report
---
```
.center[<IMG SRC=libs/titel_statistikinfo.PNG width = "150" height = auto>]
]
---
class: left, top
# Build <font color=#009ee0>statRmd</font> package
### Why build a package?
- Code organization
- Consistent documentation
- Code distribution
<!-- - it has become pretty easy to do, thanks to -->
<!-- .center[ -->
<!-- <IMG SRC="http://hexb.in/hexagons/devtools.png" width = "100" height = auto><IMG SRC="http://hexb.in/hexagons/roxygen2.png" width = "100" height = auto>] -->
- Templates
--
### Content
- RMarkdown Templates
- Some helper functions
---
class: left, top
# Load Template from <font color=#009ee0>statRmd</font>
File > New File > R Markdown > From Template
![](libs/RMarkdown_Templates.PNG)
---
background-image: url("libs/sticker-01.png")
background-position: bottom right
background-size:30%
# Keep in touch
<br>
Slides
https://statistikzh.github.io/RMeetup/
Website
https://statistik.zh.ch
Twitter
<a href="https://twitter.com/statistik_zh?ref_src=twsrc%5Etfw" class="twitter-follow-button" data-show-count="false">@statistik_zh</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<!-- .right[<IMG SRC="libs/sticker-01.png" width = auto height = "150">] -->