-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.qmd
569 lines (478 loc) · 15.4 KB
/
index.qmd
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
---
date: "`r as.Date(Sys.time())`"
format:
revealjs:
chalkboard: true
scrollable: true
theme: [serif, theme/styles.scss]
slide-number: c/t
logo: "https://www.rstudio.com/wp-content/uploads/2018/10/RStudio-Logo-Flat.png"
footer: "[https://github.com/jeremy-allen/quarto-demo](https://github.com/jeremy-allen/quarto-demo)"
code-copy: true
center-title-slide: false
include-in-header: heading-meta.html
code-link: true
code-overflow: wrap
highlight-style: a11y
height: 1080
width: 1920
link-external-newwindow: true
execute:
eval: true
echo: true
editor_options:
chunk_output_type: console
---
# {transition="slide" transition-speed="slow"}
:::{.title-center}
Quarto as reveal.js Slides
:::
:::{.center}
here is R once again being useful
:::
:::{.half-image}
![](www/icons.png){fig-alt="icons for Quarto, gt, and gtExtras"}
:::
:::{.author}
Jeremy Allen<br>
Customer Success, RStudio<br>
twitter: @jeremy_data
:::
# A demo of `Quarto`, `gt`, and `gtExtras` {transition="slide" transition-speed="slow"}
using `palmerpenguins` data
<br>
<br>
. . .
Quarto®
: Quarto is an open-source scientific and technical publishing system built on Pandoc.
. . .
gt
: With the gt package, anyone can make wonderful-looking tables using the R programming language, and a cohesive set of table parts, such as the table header, stub, column labels and spanner column labels, table body, and the table footer.
. . .
gtExtras
: The goal of gtExtras is to provide some additional helper functions to assist in creating beautiful tables with gt.
## Before we talk about Quarto {transition="slide" transition-speed="slow"}
let's build a `gt` table and experience some Quarto features
```{r}
#| message: false
#| warning: false
#| echo: true
library(tidyverse)
library(palmerpenguins)
library(gt)
library(gtExtras)
# make a table of our data
# but let's summarize by year, so first make a year column
dat <- penguins %>%
dplyr::arrange(year) %>%
mutate(year = as.factor(year)) %>%
group_by(species, island, year) %>% # order here will influence table output
summarise(across(bill_length_mm:body_mass_g, ~ mean(., na.rm = TRUE))) %>%
select(species, island, year, everything()) %>%
dplyr::arrange(species, island, year) %>%
ungroup() # experiment with and without
```
## Build the table with gt, include some gtExtras functions for colors
`gt`'s default is to produce an html table
Let's first group our data by penguin species
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|3"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt()
```
## Headers and spanners
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|5-8|9-12"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
)
```
## Formatting numbers
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|13-16"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
)
```
## Sources, footnotes, and references
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|17-19|20-26|27-30"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
) %>%
tab_source_note(
source_note = "Source: Very cold nights."
) %>%
tab_source_note(
# hitting return to start new lines so the string will stay inside the PDF
# but it will be a continuous string when it renders as the footnote
source_note = md("Reference: Horst AM, Hill AP, Gorman KB (2020).
palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package
version 0.1.0. https://allisonhorst.github.io/palmerpenguins/")
) %>%
tab_footnote(
footnote = "Only found on a single island.",
locations = cells_row_groups(groups = c("Chinstrap", "Gentoo"))
)
```
## `gtExtras` for heatmap-like colors
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|31-35"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
) %>%
tab_source_note(
source_note = "Source: Very cold nights."
) %>%
tab_source_note(
# hitting return to start new lines so the string will stay inside the PDF
# but it will be a continuous string when it renders as the footnote
source_note = md("Reference: Horst AM, Hill AP, Gorman KB (2020).
palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package
version 0.1.0. https://allisonhorst.github.io/palmerpenguins/")
) %>%
tab_footnote(
footnote = "Only found on a single island.",
locations = cells_row_groups(groups = c("Chinstrap", "Gentoo"))
) %>%
# trim gives smaller range of colors
# so the green and purples are not as dark
gt_hulk_col_numeric(bill_length_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(bill_depth_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(flipper_length_mm, trim = TRUE) # gtExtras!
```
## Change column labels and row-group lables
```{r}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|36-43|44-46"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
) %>%
tab_source_note(
source_note = "Source: Very cold nights."
) %>%
tab_source_note(
# hitting return to start new lines so the string will stay inside the PDF
# but it will be a continuous string when it renders as the footnote
source_note = md("Reference: Horst AM, Hill AP, Gorman KB (2020).
palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package
version 0.1.0. https://allisonhorst.github.io/palmerpenguins/")
) %>%
tab_footnote(
footnote = "Only found on a single island.",
locations = cells_row_groups(groups = c("Chinstrap", "Gentoo"))
) %>%
# trim gives smaller range of colors
# so the green and purples are not as dark
gt_hulk_col_numeric(bill_length_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(bill_depth_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(flipper_length_mm, trim = TRUE) %>% # gtExtras!
cols_label( # new column labels!
bill_length_mm = html("Bill Length<br>mm"),
bill_depth_mm = html("Bill Depth<br>mm"),
flipper_length_mm = html("Flipper Length<br>mm"),
body_mass_g = html("Body Mass<br>g"),
island = "Island",
year = "Year"
) %>%
tab_options(
row_group.font.weight = "800"
)
```
## Final table
what else changed?
```{r}
#| echo: false
#| message: false
#| warning: false
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
) %>%
tab_source_note(
source_note = "Source: Very cold nights."
) %>%
tab_source_note(
# hitting return to start new lines so the string will stay inside the PDF
# but it will be a continuous string when it renders as the footnote
source_note = md("Reference: Horst AM, Hill AP, Gorman KB (2020).
palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package
version 0.1.0. https://allisonhorst.github.io/palmerpenguins/")
) %>%
tab_footnote(
footnote = "Only found on a single island.",
locations = cells_row_groups(groups = c("Chinstrap", "Gentoo"))
) %>%
# trim gives smaller range of colors
# so the green and purples are not as dark
gt_hulk_col_numeric(bill_length_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(bill_depth_mm, trim = TRUE) %>% # gtExtras!
gt_hulk_col_numeric(flipper_length_mm, trim = TRUE) %>% # gtExtras!
cols_label( # new column labels!
bill_length_mm = html("Bill Length<br>mm"),
bill_depth_mm = html("Bill Depth<br>mm"),
flipper_length_mm = html("Flipper Length<br>mm"),
body_mass_g = html("Body Mass<br>g"),
island = "Island",
year = "Year"
) %>%
tab_options(
heading.align = "left",
row_group.font.weight = "800",
table.background.color = "#f0f1eb"
)
```
## Now here's a little about quarto {transition="slide" transition-speed="slow"}
The YAML for this presentation
```{verbatim, lang="yaml"}
---
date: "`r as.Date(Sys.time())`"
format:
revealjs:
chalkboard: true
scrollable: true
theme: [serif, theme/styles.scss]
slide-number: c/t
logo: "https://www.rstudio.com/wp-content/uploads/2018/10/RStudio-Logo-Flat.png"
footer: "[https://github.com/jeremy-allen/quarto-demo](https://github.com/jeremy-allen/quarto-demo)"
code-copy: true
center-title-slide: false
include-in-header: heading-meta.html
code-link: true
code-overflow: wrap
highlight-style: a11y
height: 1080
width: 1920
link-external-newwindow: true
execute:
eval: true
echo: true
editor_options:
chunk_output_type: console
---
```
<br>
I excluded title and author because I wanted to make my own title slide
## My title slide code {transition="slide" transition-speed="slow"}
:::: {.columns}
::: {.column width="60%"}
markdown that creates html divs and specifies css classes
```{verbatim, lang="markdown"}
:::{.title-center}
Quarto as reveal.js slides
:::
:::{.half-image}
![](www/icons.png){fig-alt="icons for Quarto, gt, and gtExtras"}
:::
:::{.author}
Jeremy Allen<br>
Customer Success, RStudio<br>
twitter: @jeremy_data
:::
```
:::
::: {.column width="40%"}
In my css file I have these classes defined
```{verbatim, lang="css"}
.title-center {
font-size: 2.75em;
text-align: center;
margin: auto;
}
.half-image {
width: 50%;
margin: auto;
}
.author {
font-size: 1.25em;
font-weight: 400;
text-align: left;
position: absolute;
left: 30px;
bottom: 30px;
}
```
:::
<br>
<br>
But how did I make this [two-column slide?](https://quarto.org/docs/presentations/index.html#multiple-columns)
<br>
And [different syntax highlighting](https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html#verbatim-code-chunks) on the left and right?
::::
## How slide 2 was made with animated text and definitions {transition="slide" transition-speed="slow"}
To make text appear on-click, not all at once, separate text with three dots, space between each dot
```{verbatim, lang="markdown"}
# A demo of `Quarto`, `gt`, and `gtExtras`
using `palmerpenguins` data
<br>
<br>
. . .
Quarto®
: Quarto is an open-source scientific and technical publishing system built on Pandoc.
. . .
gt
: With the gt package, anyone can make wonderful-looking tables using the R programming language, and a cohesive set of table parts, such as the table header, stub, column labels and spanner column labels, table body, and the table footer.
. . .
gtExtras
: The goal of gtExtras is to provide some additional helper functions to assist in creating beautiful tables with gt.
```
The markdown convention below, shows the word in bold and offsets the definition below
(not unique to slides)
```{verbatim, lang="markdown"}
word
: definition goes here
```
## How code and ouput slides were made {transition="slide" transition-speed="slow"}
| Inside an r code chunk, the usual knitr chunk options are used first
| `output-location: column` is used to split code and output into columns
| `code-line-numbers: "|17-19|20-26|27-30"` steps through code highlights on click
```{verbatim, lang="r"}
#| echo: true
#| message: false
#| warning: false
#| output-location: column
#| code-line-numbers: "|17-19|20-26|27-30"
# table using gt package
dat %>%
dplyr::group_by(species) %>% # add a grouping variable and drop stub info
gt() %>%
tab_header(
title = md("**Penguin Anatomical Changes**"), #wrapped in md() for markdown
subtitle = "By species, island, and year from 2007-2009"
) %>%
tab_spanner( # tab spanner!
label = "mean anatomical measures",
columns = c(bill_length_mm:body_mass_g)
) %>%
fmt_number(
columns = bill_length_mm:body_mass_g,
decimals = 1
) %>%
tab_source_note(
source_note = "Source: Very cold nights."
) %>%
tab_source_note(
# hitting return to start new lines so the string will stay inside the PDF
# but it will be a continuous string when it renders as the footnote
source_note = md("Reference: Horst AM, Hill AP, Gorman KB (2020).
palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package
version 0.1.0. https://allisonhorst.github.io/palmerpenguins/")
) %>%
tab_footnote(
footnote = "Only found on a single island.",
locations = cells_row_groups(groups = c("Chinstrap", "Gentoo"))
)
```
# Your turn! To get started {background-image="www/paper.png" background-size="cover"}
- [quarto.org](https://quarto.org/)
- [gt](https://gt.rstudio.com/index.html)
- [gtExtras](https://jthomasmock.github.io/gtExtras/)
- [palmerpenguins](https://allisonhorst.github.io/palmerpenguins/)
<br>
code at <https://github.com/jeremy-allen/quarto-demo>
:::{.credit}
Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/s/photos/paper?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
:::
:::{.author}
Jeremy Allen<br>
Customer Success, RStudio<br>
twitter: @jeremy_data
:::