-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
277 lines (203 loc) · 6.78 KB
/
README.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
set.seed(seed = 2021)
library("ggplot2")
theme_set(theme_minimal() +
theme(text = ggplot2::element_text(family = "Roboto Condensed")))
```
# riskviewer
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
<!-- badges: end -->
The goal of riskviewer is to provide a modern implementation of the "Risk Characterisation Theatre" originally proposed by Erik Rifkin and Edward Bouwer in their 2007 book "[The illusion of certainty: Health Benefits and Risks](https://link.springer.com/book/10.1007/978-0-387-48572-0)".
## Why is this useful?
- uncertainty, embedded
- instinctive understanding of risk assessment figures based on real-world-scenarios
More context in the package vignette.
## Preliminary notes
The package has been created as a quick experimentation of how it would be possible to implement the risk characterisation theatre. At this stage, the codebase is still messy and poorly documented. Customisation of parameters is largely untested, so anything differing significantly from the examples documented in the README and vignette will likely not work.
### Common issues
The output really works only when exported at suitable sizes. For example, for a basic combination of two airplanes such as the first example in this readme, export with width set 12 and height set to 14 and you'll get the expected result. E.g. based on the example below:
```{r example_export, eval = FALSE}
plane_1 + plane_2
ggplot2::ggsave(filename = "plane_combo.png",
plot = plane_1 + plane_2,
width = 12,
height = 14,
bg = "white")
```
Beware of fonts: if you don't have either "Roboto Condensed" or "Roboto Mono" installed and available in R, the output will probably just look completely wrong. You can either try with other fonts, or use default fonts: defaults fonts should work (or at least, they do on my computer), even if the look less satisfying.
In order to check if a given font is available, try:
```{r font checks, eval = FALSE}
library("extrafont")
#extrafont::font_import()
"Roboto Condensed" %in% fonts()
"Roboto Mono" %in% fonts()
```
## Installation
You can install `riskviewer` from [GitHub](https://github.com/EDJNet/riskviewer) with:
``` r
# install.packages("remotes")
remotes::install_github("EDJNet/riskviewer")
```
## Examples
At this stage, this package provides two formats for representing risk.
### Airplane
```{r airplane_example_AB, fig.width=12, fig.height=14, fig.align='center'}
library("riskviewer")
library("patchwork")
plane_1 <- rv_create_airplane(
risk_ratio = 0.1,
rows = 33,
title = "Scenario A",
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono"
)
plane_2 <- rv_create_airplane(
risk_ratio = 0.3,
rows = 33,
title = "Scenario B",
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono"
)
plane_1 + plane_2
```
If more than one airplane is needed:
```{r airplane_example_combo, fig.width=16, fig.height=14, fig.align='center'}
rv_create_airplane_combo(
risk_ratio = 0.01,
number_of_planes = 3,
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono", guides = NULL
)
```
```{r airplane_example_2, fig.width=12, fig.height=30, fig.align='center'}
rv_create_airplane_combo(
risk_ratio = 0.001,
number_of_planes = 5,
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono",
legend_position = "none",
ncol = 3,
nrow = 2, guides = NULL
)
```
Or, using more than one risk consideration:
```{r airplane_example_more, fig.width=8, fig.height=16, fig.align='center'}
risk_ratio <- tibble::tribble(
~Risk, ~Ratio,
"Hospitalization", 0.3,
"Death", 0.1
)
combo_gg <- rv_create_airplane_combo(
risk_ratio = risk_ratio,
number_of_planes = 2,
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono",
legend_position = "bottom",
guides = "collect"
)
combo_gg +
patchwork::plot_annotation(
title = "Risk caused by x for people aged xx", caption = "Made with `riskviewer`, a tool by EDJNet",
theme = ggplot2::theme(plot.title = ggplot2::element_text(size = 24, family = "Roboto Condensed", hjust = 0.5))
)
```
## Compact airplane
```{r compact_one, fig.width=3, fig.height=6}
combo_gg <- rv_create_airplane_combo(
risk_ratio = risk_ratio,
number_of_planes = 2,
font_family = "Roboto Condensed",
font_family_seats = "Roboto Mono",
legend_position = "bottom",
guides = "collect",
compact = TRUE
)
combo_gg
```
The compact format makes it easier to have many planes:
```{r compact_many, fig.width=6, fig.height=9, fig.align='center'}
rv_create_airplane_combo(
risk_ratio = 0.002,
number_of_planes = 10,
compact = TRUE,
font_family = "Roboto Condensed",
legend_position = "none",
ncol = 5,
nrow = 2,
guides = NULL
) +
patchwork::plot_annotation(
title = "This risk hits about 2 people out of one thousand", caption = "Made with `riskviewer`, a tool by EDJNet",
theme = ggplot2::theme(plot.title = ggplot2::element_text(size = 16, family = "Roboto Condensed", hjust = 0.5))
)
```
## Animate transition between different risk scenarios
(currently broken)
```{r eval = FALSE}
gg_airplane_animated <- tibble::tribble(
~Risk, ~Ratio,
"Age 20", 0.009,
"Age 30", 0.027,
"Age 40", 0.048,
"Age 50", 0.085,
"Age 60", 0.155,
"Age 70", 0.244,
"Age 80", 0.317
) %>%
rv_create_airplane_animation(title = "Risk 1")
gganimate::animate(
plot = gg_airplane_animated,
# renderer = gganimate::ffmpeg_renderer(),
height = 8,
width = 2,
units = "in",
res = 150
)
```
### Arena
It is possible to create a ggplot object that looks like the seatmap of an arena, but this implies using two different projections, combining the graph, and leaving the top half empty.
```{r arena005}
library("riskviewer")
rv_create_arena(
ratio = 0.05,
title = "The risk you face",
ggplot = FALSE,
quality = "low"
)
```
```{r arena03}
library("riskviewer")
rv_create_arena(ratio = 0.3, ggplot = TRUE)
```
## Combine more
```{r arena_combo}
graphs <- list(
rv_create_arena(ratio = 0.1, title = "Scenario A", ggplot = TRUE),
rv_create_arena(ratio = 0.8, title = "Scenario B", ggplot = TRUE)
)
rv_img(plot = graphs, stack = TRUE, quality = "medium")
```
```{r arena_combo_no_stack}
rv_img(plot = graphs, stack = FALSE, quality = "medium")
```
## Export in other formats
```{r export, eval=FALSE}
ggplot2::ggsave(
filename = "risk_arena.svg",
plot = rv_create_arena(ratio = 0.1, ggplot = TRUE),
width = 10,
height = 10,
units = "in"
)
```