-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_dashboard.Rmd
493 lines (331 loc) · 9.63 KB
/
02_dashboard.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
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
---
title: "`r params$doc_title`"
output:
flexdashboard::flex_dashboard:
orientation: rows
css: style.css
params:
doc_title: "LFS industry profiles"
editor_options:
chunk_output_type: console
---
```{r}
dash_required <- c("flexdashboard",
"knitr",
"tidyverse",
"crosstalk",
"DT",
"plotly",
"heatmaply",
"patchwork",
"fpp3",
"conflicted")
source(here::here("R","functions.R"))
invisible(lapply(dash_required, load_package))
conflicts_prefer(dplyr::filter)
conflicts_prefer(dplyr::mutate)
conflicts_prefer(plotly::layout)
all_with_mapping <- read_rds(here::here("temp","all_with_mapping.rds"))
for_ts_plots <- read_rds(here::here("temp","for_ts_plots.rds"))
for_heatmaps <- all_with_mapping%>%
filter(agg_level=="high")%>%
ungroup()%>%
select(agg_level, name, data)
for_tables <- read_rds(here::here("temp","for_tables.rds"))%>%
tidyr::unnest(data)%>%
ungroup()%>%
mutate(Characteristic = if_else(Characteristic=="", NA_character_, Characteristic))%>%
fill(Characteristic, .direction = "down")%>%
mutate(Industry= str_replace_all(Industry, " ", " "))
Shared_table <- SharedData$new(for_tables)
industries <- unique(for_tables$parent)|>
unique()
for_plots <- read_rds(here::here("temp","for_plots.rds"))%>%
dplyr::rename(Characteristic=name)%>%
tidyr::unnest(data)%>%
ungroup()
Shared_em <- SharedData$new(for_plots%>%filter(Characteristic=="Employed"), group = "industry")
Shared_ft <- SharedData$new(for_plots%>%filter(Characteristic=="Full-Time"), group = "industry")
Shared_lf <- SharedData$new(for_plots%>%filter(Characteristic=="Labour Force"), group = "industry")
Shared_pt <- SharedData$new(for_plots%>%filter(Characteristic=="Part-Time"), group = "industry")
Shared_un <- SharedData$new(for_plots%>%filter(Characteristic=="Unemployed"), group = "industry")
Shared_ur <- SharedData$new(for_plots%>%filter(Characteristic=="Unemployment Rate"), group = "industry")
for_pca<- read_rds(here::here("temp","for_pca.rds"))%>%
mutate(biplot=map(pcs, biplot_wrapper))
page_titles <- c(c("Title Page",#replace with your page titles
"Data table",
"Level Changes",
"Percent Changes",
"Heatmaps",
"Biplots"
),
industries)
```
# `r page_titles[1]` {data-navmenu="Table of Contents"}
## Row {.background-banner}
<br><br><br><br><br><br><br><br>
<h3>Monthly Labour Force Survey, aggregated to 3 levels:</h3>
- 16 high level industries.
- 76 medium level industries.
- 56 low level industries.
# `r page_titles[2]` {data-navmenu="Table of Contents"}
## Inputs {.sidebar}
### Inputs:
```{r}
filter_select(
id = "parent",
label = "Choose an industry",
sharedData = Shared_table,
group = ~ `parent`,
multiple = FALSE
)
filter_select(
id = "char",
label = "Choose a characteristic",
sharedData = Shared_table,
group = ~`Characteristic`,
multiple = FALSE
)
```
```{js, echo=FALSE}
<!-- function filter_default(){ -->
<!-- document.getElementById("parent").getElementsByClassName("selectized")[0].selectize.setValue("Construction", false) -->
<!-- document.getElementById("char").getElementsByClassName("selectized")[0].selectize.setValue("Employed", false) -->
<!-- } -->
<!-- $(document).ready(filter_default); -->
```
## Column
### `r page_titles[2]`
```{r}
sketch = htmltools::withTags(table(
class = 'display',
thead(
tr(
th(class="dt-center", colspan = 3, ''),
th(class="dt-center", colspan = 3, 'Monthly'),
th(class="dt-center", colspan = 2, 'Year to Date',
th(class="dt-center", colspan = 3, 'Level Change'),
th(class="dt-center", colspan = 3, 'Percent Change'),
)
),
tr(
lapply(names(for_tables), th)
)
)
))
Shared_table %>%
DT::datatable(
container = sketch,
rownames = FALSE,
escape = FALSE,
extensions = c('Buttons', 'FixedColumns'),
class = 'cell-border stripe',
options = list(
pageLength = 100,
dom = 'Bfrtip',
scrollX = TRUE,
columnDefs = list(list(visible=FALSE, targets = c(0,1))),
buttons = c('csv', 'excel')))
```
# `r page_titles[3]` {data-navmenu="Table of Contents"}
## Inputs {.sidebar}
### `r page_titles[3]`
```{r}
filter_select(
id = "high_plots",
label = "Choose an aggregation level",
sharedData = Shared_em,
group = ~`agg_level`,
multiple = FALSE
)
```
## Row {data-height="500"}
### Employed
```{r}
level_change_plot(Shared_em)
```
### Full time
```{r}
level_change_plot(Shared_ft)
```
### Labour Force
```{r}
level_change_plot(Shared_lf)
```
## Row {data-height="500"}
### Part time
```{r}
level_change_plot(Shared_pt)
```
### Unemployed
```{r}
level_change_plot(Shared_un)
```
### Unemployment rate
```{r}
level_change_plot(Shared_ur)
```
# `r page_titles[4]` {data-navmenu="Table of Contents"}
## Inputs {.sidebar}
- Aggregation level choice is on previous page (to ensure correspondence.)
### `r page_titles[4]`
## Row {data-height="500"}
### Employed
```{r}
percent_change_plot(Shared_em)
```
### Full time
```{r}
percent_change_plot(Shared_ft)
```
### Labour Force
```{r}
percent_change_plot(Shared_lf)
```
## Row {data-height="500"}
### Part time
```{r}
percent_change_plot(Shared_pt)
```
### Unemployed
```{r}
percent_change_plot(Shared_un)
```
### Unemployment rate
```{r}
percent_change_plot(Shared_ur)
```
# `r page_titles[5]` {data-navmenu="Table of Contents"}
## Column {.tabset}
### Employed
```{r}
my_heatmap("Employed")
```
### Unemployed
```{r}
my_heatmap("Unemployed")
```
### Full-Time
```{r}
my_heatmap("Full-Time")
```
### Part-Time
```{r}
my_heatmap("Part-Time")
```
### Labour Force
```{r}
my_heatmap("Labour Force")
```
### Unemployment Rate
```{r}
my_heatmap("Unemployment Rate")
```
# `r page_titles[6]` {data-navmenu="Table of Contents"}
## Inputs {.sidebar data-width=600}
### TL;DR
- Education is the most seasonal industry due to 10 month contracts.
- Accommodation and Food is the most "spiky" due to COVID.
- Professional Services and Public Administration are the most trending industries.
### Background:
- Principal Component Analysis (PCA) is a way to get the most informative "view" of high dimension data.
- Here we use 9 measures of time series for the 16 major industries.
- The goal is to characterize the industries in terms of these measures.
- It is impossible to visualize in 9 dimensions: PCA rotates the data cloud to get the most informative view.
- An analogy might help: Suppose that you need to identify a 3d object from a 2d representation of that object (e.g. a photo of the object). To make the example stark consider an 8.5 by 11 sheet of paper.
- PCA rotates the object in such a way that the photo captures as much of (the variability of) the object as possible.
- PCA would rotate the piece of paper so the x axis is the hypotenuse between non-adjacent corners, the y axis is perpendicular to the x axis and the z axis (the thickness of the paper) is hidden from view.
- This can be contrasted with the least informative view of the paper: the side view, which in a picture would appear to be a (one dimensional) line of length 8.5.
### Measures:
- Some of the measures have evocative names, others less so.
- Spectral Entropy: a measure of predictability, with a range 0,1. e.g. white noise has a spectral entropy of 1, sin(x) has a spectral entropy of 0.
- Hurst Coefficient: a measure of persistence or "mild vs. wild". e.g. white noise has a Hurst Coefficient of .5, a mean reverting series has a coefficient <.5, and persistent series has a coefficient >.5.
## Column {.tabset}
### Employed
```{r}
get_biplot("Employed")
```
### Unemployed
```{r}
get_biplot("Unemployed")
```
### Full time
```{r}
get_biplot("Full-Time")
```
### Part time
```{r}
get_biplot("Part-Time")
```
### Labour Force
```{r}
get_biplot("Labour Force")
```
### Unemployment rate
```{r}
get_biplot("Unemployment Rate")
```
# `r page_titles[7]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[7])
```
# `r page_titles[8]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[8])
```
# `r page_titles[9]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[9])
```
# `r page_titles[10]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[10])
```
# `r page_titles[11]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[11])
```
# `r page_titles[12]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[12])
```
# `r page_titles[13]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[13])
```
# `r page_titles[14]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[14])
```
# `r page_titles[15]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[15])
```
# `r page_titles[16]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[16])
```
# `r page_titles[17]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[17])
```
# `r page_titles[18]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[18])
```
# `r page_titles[19]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[19])
```
# `r page_titles[20]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[20])
```
# `r page_titles[21]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[21])
```
# `r page_titles[22]` {data-navmenu="Table of Contents"}
```{r}
make_patchwork(page_titles[22])
```