-
Notifications
You must be signed in to change notification settings - Fork 0
/
jcp_hh_fam_page.Rmd
139 lines (121 loc) · 3.16 KB
/
jcp_hh_fam_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
---
title: "Monthly number of households on Universal Credit by family type"
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_hh_la_fam.rdata")
uc_hh_la_fam_ts <- uc_hh_la_fam |>
select(`Local authority` = 1,
Month,
n_hh = `Households on Universal Credit`,
fam = `Family Type`) %>%
mutate(Month = dmy(paste(1, Month))) %>%
mutate(fam = factor(
fam,
levels = c(
"Single, no children",
"Single, with children",
"Couple, no children",
"Couple, with children",
"Unknown or missing family type"
)
)) %>%
arrange(`Local authority`, desc(Month), desc(fam)) %>%
group_by(`Local authority`, Month) |>
mutate(
tooltip = paste0(
"Local authority: ",
`Local authority`,
"\nMonth: ",
Month,
"\nNumber of households, ",
str_to_lower(fam),
": ",
n_hh
),
n_hh = cumsum(n_hh),
) %>%
group_by(`Local authority`) %>%
mutate(p_p = n_hh / max(n_hh),
fam = fct_reorder(fam, p_p, max, .desc = FALSE)) %>%
ungroup() %>%
select(-n_hh) %>%
pivot_wider(names_from = fam, values_from = c(p_p, tooltip))
uc_hh_shared <- SharedData$new(uc_hh_la_fam_ts)
```
```{r}
filter_select("la", "Local authority", uc_hh_shared, ~`Local authority`, allLevels = FALSE,
# selected = "Aberdeen City Council",
multiple = FALSE
)
```
```{r}
uc_hh_shared %>%
plot_ly(
x = ~ Month,
y = ~ `p_p_Single, no children`,
type = "scatter",
mode = "line",
fill = "tozeroy",
name = "Single, no children",
text = ~ `tooltip_Single, no children`,
hoverinfo = "text"
) %>%
add_trace(
y = ~ `p_p_Single, with children`,
text = ~ `tooltip_Single, with children`,
name = "Single, with children"
) %>%
add_trace(
y = ~ `p_p_Couple, no children`,
text = ~ `tooltip_Couple, no children`,
name = "Couple, no children"
) %>%
add_trace(
y = ~ `p_p_Couple, with children`,
text = ~ `tooltip_Couple, with children`,
name = "Couple, with children"
) %>%
add_trace(
y = ~ `p_p_Unknown or missing family type`,
text = ~ `tooltip_Unknown or missing family type`,
name = "Unknown or missing family type"
) %>%
config(displayModeBar = FALSE) %>%
layout(
xaxis = list(fixedrange = TRUE),
xaxis2 = list(fixedrange = TRUE),
yaxis = list(fixedrange = TRUE, title = "Proportion of max households 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)
```