-
Notifications
You must be signed in to change notification settings - Fork 0
/
ninja-knitting-template.Rmd
99 lines (79 loc) · 2.66 KB
/
ninja-knitting-template.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
---
pagetitle: "Ninja knitting with Star Wars"
output:
xaringan::moon_reader:
css: ["default", "styles/custom.css", "styles/custom-fonts.css"]
seal: false
lib_dir: libs
self_contained: true
nature:
countIncrementalSlides: false
params:
name: NULL
---
layout: true
```{r setup, include=FALSE}
# Load packages
library(dplyr)
library(ggplot2)
library(knitr)
library(fontawesome)
# Set chunk options
opts_chunk$set(
echo = FALSE, warning = FALSE, message = FALSE,
fig.width = 10
)
```
```{r prep-url, include=FALSE}
# Generate a link to Wookiepedia for each character
char_data <- filter(starwars_complete, name == params$name) %>%
mutate(
url = paste0(
"https://starwars.fandom.com/wiki/",
str_replace(name, " ", "_")
)
)
```
```{r prep-plot, include=FALSE}
# Build a plot of mass vs height for each character
char_plot <- starwars_complete %>%
ggplot(aes(x = mass, y = height)) +
geom_point(size = 5, shape = 20, color = "yellow") +
geom_point(
aes(x = char_data$mass, y = char_data$height),
size = 10, shape = 20, color = "red"
) +
labs(x = "Mass (kg)", y = "Height (cm)") +
theme_classic() +
theme(
panel.background = element_rect(fill = "black"),
plot.background = element_rect(color = "black", fill = "black"),
text = element_text(family = "Libre Franklin"),
axis.text = element_text(color = "yellow", size = 15),
axis.title = element_text(color = "yellow", size = 20),
axis.title.x = element_text(margin = margin(t = 30, r = 0, b = 0, l = 0)),
axis.title.y = element_text(margin = margin(t = 0, r = 30, b = 0, l = 0)),
axis.ticks = element_line(color = "yellow")
)
```
---
class: middle, center
# `r char_data$name`
### A micro-dossier
<font size=50>`r fa("r-project", fill = "yellow")` `r fa("journal-whills", fill = "yellow")`</font>
Demo of iterative rendering of [{xaringan}](https://slides.yihui.org/xaringan/#1) slides with params using [{purrr}](https://purrr.tidyverse.org/)
[Data source](https://dplyr.tidyverse.org/reference/starwars.html) | [Slide source](https://www.github.com/matt-dray/ninja-knitting/) | [Blog post](https://www.rostrum.blog/2020/03/12/knit-with-params/)
---
class: middle
`r char_data$name`
* is a `r paste(char_data$gender, tolower(char_data$species), "from", char_data$homeworld)`
* has mass `r char_data$mass` kg and height `r char_data$height` cm
* has `r char_data$eye_color` eyes `r ifelse(char_data$hair_color == "none", "", paste("and", str_replace(char_data$hair_color, ", ", "/"), "hair"))`
<br>
Find out more on [Wookiepedia](`r char_data$url`)
---
class: middle
`r paste0(pull(char_data, name), "'s size in context")`
```{r plot}
char_plot
```