-
Notifications
You must be signed in to change notification settings - Fork 0
/
uc_pp_la_cond_page.Rmd
146 lines (129 loc) · 3.42 KB
/
uc_pp_la_cond_page.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
---
title: "Monthly number of people on Universal Credit by conditionality regime"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
---
```{css, echo = FALSE}
#la{
position: absolute;
z-index: 100;
left: 100px;
max-width: 60%;
min-width: 600px
}
```
```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(tidyverse)
library(crosstalk)
library(lubridate)
library(htmlwidgets)
library(SPHSUgraphs)
`-.gg` <- function(e1, e2) e2(e1)
theme_set(theme_sphsu_light())
load(file = "data/uc_pp_la_cond.rdata")
uc_pp_la_cond_ts <- uc_pp_la_cond_n |>
select(cond = `Conditionality Regime`,
la = `National - Regional - LA - OAs`,
Month,
uc = `People on Universal Credit`) |>
mutate(Month = my(Month)) |>
filter(cond != "Total",
Month != ymd("2023-06-01")) |>
mutate(cond = factor(
cond,
levels = c(
"Unknown or missing regime",
"Planning for work",
"Preparing for work",
"Working - no requirements",
"Working - with requirements",
"No work requirements",
"Searching for work"
)
)) |>
arrange(la, desc(Month), cond) |>
group_by(la, Month) |>
mutate(
tooltip = paste0(
"Local authority: ", la,
"\nMonth: ", Month,
"\nNumber of people ", str_to_lower(cond), ": ", uc
),
uc = cumsum(uc),
) |>
group_by(la) |>
mutate(p_p = uc/max(uc)) |>
ungroup() |>
select(-uc) |>
pivot_wider(names_from = cond, values_from = c(p_p, tooltip))
uc_pp_shared <- SharedData$new(uc_pp_la_cond_ts)
```
```{r}
filter_select("la", "Local authority", uc_pp_shared, ~la, allLevels = FALSE,
# selected = "Aberdeen City Council",
multiple = FALSE
)
```
```{r}
uc_pp_shared %>%
plot_ly(
x = ~ Month,
type = "scatter",
mode = "line",
fill = "tozeroy",
hoverinfo = "text",
y = ~ `p_p_Searching for work`,
text = ~ `tooltip_Searching for work`,
name = "Searching for work"
) %>%
add_trace(
y = ~ `p_p_No work requirements`,
text = ~ `tooltip_No work requirements`,
name = "No work requirements"
) %>%
add_trace(
y = ~ `p_p_Working - with requirements`,
text = ~ `tooltip_Working - with requirements`,
name = "Working - with requirements"
) %>%
add_trace(
y = ~ `p_p_Working - no requirements`,
text = ~ `tooltip_Working - no requirements`,
name = "Working - no requirements"
) %>%
add_trace(
y = ~ `p_p_Preparing for work`,
text = ~ `tooltip_Preparing for work`,
name = "Preparing for work"
) %>%
add_trace(
y = ~ `p_p_Planning for work`,
text = ~ `tooltip_Planning for work`,
name = "Planning for work"
) %>%
add_trace(
y = ~ `p_p_Unknown or missing regime`,
text = ~ `tooltip_Unknown or missing regime`,
name = "Unknown or missing regime"
) %>%
config(displayModeBar = FALSE) %>%
layout(
xaxis = list(fixedrange = TRUE),
xaxis2 = list(fixedrange = TRUE),
yaxis = list(fixedrange = TRUE, title = "Proportion of max persons on UC"),
yaxis2 = list(fixedrange = TRUE),
legend = list(x = 0.1, y = 0.75,
itemclick = FALSE,
itemdoubleclick = FALSE)
)
```
```{js}
function filter_default() {
document.getElementById("la").getElementsByClassName("selectized")
[0].selectize.setValue("Aberdeen City", false);
}
$(document).ready(filter_default)
```