-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.Rmd
181 lines (130 loc) · 6.36 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
---
author: "CorrelAid Core Team"
title: CorrelAid Data Journey
date: "`r Sys.Date()`"
knit: "bookdown::render_book"
bibliography: [book.bib, packages.bib]
link-citations: yes
lot: yes
lof: yes
output:
bookdown::gitbook:
fig_caption: yes
site: bookdown::bookdown_site
favicon: resources/images/favicon.ico
cover-image: resources/images/logo.png
description: "A guide to authoring books with R Markdown, including how to generate figures and tables, and insert cross-references, citations, HTML widgets, and Shiny apps in R Markdown. The book can be exported to HTML, PDF, and e-books (e.g. EPUB). The book style is customizable. You can easily write and preview the book in RStudio IDE or other editors, and host the book wherever you want (e.g. bookdown.org)."
---
```{r setup, echo=FALSE, include=FALSE}
library(gt)
# automatically create a bib database for R packages
knitr::write_bib(c(
.packages(), 'bookdown', 'knitr', 'rmarkdown'
), 'packages.bib')
```
# {-}
```{r logo, echo = FALSE, fig.cap="cover image"}
knitr::include_graphics("resources/images/logo.png")
```
<a href="https://doi.org/10.5281/zenodo.2553043"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.2553043.svg?branch=master" alt="DOI"></a>
<a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/3.0/us/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/3.0/us/88x31.png" /></a><br /> This work is licensed under [a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License](https://creativecommons.org/licenses/by-nc-sa/3.0/us/). Refer to [its Zenodo DOI](https://doi.org/10.5281/zenodo.2553043) to cite it.
# Einführung {#intro}
Um ein neues *Chapter* zu erstellen, legt man eine neue Rmd Datei in RStudio an (Datei -> Neu -> RMarkdown). Der Dateiname sollte durchnummeriert sein (vgl. `02-sample-chapter.Rmd`).
Den YAML Header (alles zwischen `---`) kann man löschen. Wichtig ist, dass das Dokument mit einer Markdown Überschrift beginnt:
`# My Chapter`
Markdown provides an easy way to make standard types of formatted text, like
- *italics*
- **bold**
- `code`
- [links](rmarkdown.rstudio.com)
- etc.
Ein Zitat kann man so machen:
> this is a quote.
(A very cool person)
## Citations {#citations}
You can write citations, too. For example, we are using the **bookdown** package in this sample book, which was built on top of R Markdown and **knitr** [@xie2015].
We can also cite R Packages, e.g. knitr [@R-knitr] or: Rmarkdown is a package by @R-rmarkdown
@center_for_data_science_and_public_policy_university_of_chicago_data_2018
## Tables
```{r echo=FALSE, message=FALSE}
# load data
drm <- readr::read_csv("resources/tables/datenreifegradmodell.csv", quote = "\"", na = c(""))
drm[is.na(drm)] <- ""
```
### kable
```{r, drm, echo=FALSE}
k <- knitr::kable(drm, format = "html", caption = "Datenreifegrad sozialer Organisationen")
k %>%
kableExtra::kable_styling(font_size = 14) %>%
kableExtra::column_spec(which(colnames(drm) == "Ausgezeichnet"), background = "#1a9641", include_thead = TRUE) %>%
kableExtra::column_spec(which(colnames(drm) == "Fortgeschritten"), background = "#a6d96a", include_thead = TRUE) %>%
kableExtra::column_spec(which(colnames(drm) == "Ausreichend"), background = "#fdae61", include_thead = TRUE) %>%
kableExtra::column_spec(which(colnames(drm) == "Unzureichend"), background = "#d7191c", include_thead = TRUE)
```
we can reference kable tables: see \@ref(tab:drm)
### gt
```{r echo=FALSE}
gt_tbl <- gt::gt(drm)
# Show the gt Table
gt_tbl <- gt_tbl %>%
tab_header(
title = "Data Maturity Framework",
subtitle = "Ein Modellierungsframework"
) %>%
tab_source_note(
source_note = "Quelle: Center for Data Science & Public Policy, Data Maturity Framework, University of Chicago."
) %>%
opt_row_striping(row_striping = FALSE)
gt_tbl <- gt_tbl %>%
tab_style(
style = list(cell_fill(color = "#d7191c")),
locations = list(cells_body(columns = vars(Unzureichend)), cells_column_labels(vars(Unzureichend)))
) %>%
tab_style(
style = list(cell_fill(color = "#fdae61")),
locations = list(cells_body(columns = vars(Ausreichend)), cells_column_labels(vars(Ausreichend)))
) %>%
tab_style(
style = list(cell_fill(color = "#a6d96a")),
locations = list(cells_body(columns = vars(Fortgeschritten)), cells_column_labels(vars(Fortgeschritten)))
) %>%
tab_style(
style = list(cell_fill(color = "#1a9641")),
locations = list(cells_body(columns = vars(Ausgezeichnet)), cells_column_labels(vars(Ausgezeichnet)))
)
gt_tbl
```
sadly, referencing is not implemented yet for gt.
## Images {#images}
You can include images like so:
![CorrelAid logo](resources/images/logo.png)
you can control width or height in different units like so:
controlling the width:
![CorrelAid logo](resources/images/logo.png){width=1in}
controlling the height:
![CorrelAid logo](resources/images/logo.png){height=2cm}
the part in '[]' is the alt text. it is important for vision-impaired people to specify this because screenreaders will rely on them.
You can also use R to include images. One advantage is that we can use the chunk label for crossreferencing. For that to work, we need to provide a caption to the figure by using the chunk option `fig.cap`.
```{r ca-logo, fig.cap="A caption"}
knitr::include_graphics("resources/images/logo.png")
```
control width / height using different [chunk options](https://yihui.org/knitr/options/#plots)
```{r ca-logo2, out.width=200}
knitr::include_graphics("resources/images/logo.png")
```
```{r ca-logo3, out.width="30%"}
knitr::include_graphics("resources/images/logo.png")
```
```{r cars-plot, fig.cap="a plot from the cars dataset"}
plot(cars$speed)
```
## Cross-referencing {#crossref}
Goes to title logo \@ref(fig:logo)
goes to first small logo \@ref(fig:ca-logo)
goes to cars plot \@ref(fig:cars-plot)
goes to kable table \@ref(tab:drm)
reference another section : \@ref(intro), you can also hyperlink a section: Read more about it in the [intro section](#intro). Read more about RMarkdown [here](#rmarkdown)
## Ressourcen
- [RMarkdown Cheatsheet](https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf?_ga=2.165041471.1414238925.1592201672-701677801.1580388718)
- [RMarkdown RStudio Kurs](https://rmarkdown.rstudio.com/lesson-1.html)
- [citations](https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html)