-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qmd
287 lines (225 loc) · 7.43 KB
/
main.qmd
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
---
title: "Birth indicators in France"
format:
dashboard:
orientation: rows
nav-buttons:
- icon: github
href: https://github.com/kantiles/demo_isd
mainfont: Outfit
theme:
- custom.scss
---
```{r}
#| label: import_data
#| output: false
source(here::here("R/export_data_ojs.R"))
```
```{ojs}
//| output: false
// get data from R
data = transpose(data_init)
data_grid = transpose(data_grid_init)
```
# Geography
## {.sidebar}
```{ojs}
//| output: false
// topojson file from https://github.com/InseeFrLab/cartiflette
depFrance = FileAttachment("data/raw.topojson").json();
depContours = topojson.feature(depFrance, "France");
projection = d3
.geoMercator()
.center([2, 47]) // GPS of location to zoom on
.scale(800) // This is like the zoom
.translate([220 / 2, 220 / 2]);
pathGenerator = d3.geoPath(projection);
// France map function
// inspired by https://observablehq.com/@danielkerrigan/synchronized-map-input
frMap = (value) => {
const svg = d3.create("svg").attr("width", 220).attr("height", 220);
const statesDrawn = svg
.selectAll(".state")
.data(depContours.features)
.join("path")
.attr("class", "state")
.attr("d", pathGenerator)
.attr("fill", "white")
.attr("stroke", "grey")
// sending updates:
// when a state is clicked, set the value property and emit an input event
.on("click", (event, d) =>
svg.property("value", d.properties.INSEE_DEP).dispatch("input")
);
// receiving updates:
// update the map in the setter
Object.defineProperty(svg.node(), "value", {
get() {
return value;
},
set(v) {
value = v;
statesDrawn
.attr("fill", (d) => (d.properties.INSEE_DEP === v ? "blue" : "white"))
.attr("opacity", (d) => (d.properties.INSEE_DEP === v ? 0.5 : 1.0));
},
});
// initial value
svg.property("value", value);
return svg.node();
}
```
```{ojs}
// bind inputs of select & map
Inputs.bind(
Inputs.select(
new Map(depContours.features.map(d => [d.properties.LIBELLE_DEPARTEMENT, d.properties.INSEE_DEP])),
{sort: true, label: "Select an area: ", format: ([name, value]) => `${name}`}),
viewof dep
)
viewof dep = frMap("75")
```
```{ojs}
//| output: false
// filter data
filtered = data.filter(function(x) {
return dep == x.code_geo ;
})
// filter for each graph
// to do - function to wrap that
filtered_c22 = filtered.filter(function(x) {
return x.isd == "Premature births by week of amenorrhea"})
filtered_c23 = filtered.filter(function(x) {
return x.isd == "Births according to child weight"})
filtered_c24 = filtered.filter(function(x) {
return x.isd == "Births according to mother age"})
// last year
data_last = data.filter(function(x) {
return x.annee == 2022})
filtered_last = data_last.filter(function(x) {
return dep == x.code_geo})
```
:::sidebar-note
Built by [Thomas Vroylandt](https://tvroylandt.github.io/personal/) at [Kantiles](https://kantiles.com/).
:::
## Column
### Row {height=15%}
```{ojs}
//| output: false
// see https://github.com/quarto-dev/quarto-cli/issues/8823
value_box1 = filtered_last.filter(function(x) {
return x.indicator == "Under 20 years old"})[0]["value"]
```
::: {.valuebox icon="person-standing-dress" color="primary"}
**`{ojs} value_box1`**% of births from mother aged under 20
:::
```{ojs}
//| output: false
value_box2 = filtered_last.filter(function(x) {
return x.indicator == "Less than 2.5kg"})[0]["value"]
```
::: {.valuebox icon="rulers" color="danger"}
**`{ojs} value_box2`**% of babies borned under 2.5kg
:::
```{ojs}
//| output: false
value_box3 = filtered_last.filter(function(x) {
return x.indicator == "Before 37 weeks"})[0]["value"]
```
::: {.valuebox icon="calendar-week" color="warning"}
**`{ojs} value_box3`**% of births before 37 weeks
:::
### Row
```{ojs}
//| title: Births by mother age - comparison across areas
// todo : function
// barcode with value
Plot.plot({
x: {label: "%"},
y: {label: null,
domain:["Under 20 years old",
"20-24 years old",
"25-29 years old",
"30-34 years old",
"35-39 years old",
"40 years old and above"]},
marginLeft: 130,
marks : [
Plot.tickX(data_last.filter(function(x) {
return x.isd == "Births according to mother age"}), {x: "value", y: "indicator", stroke:"lightgrey", channels: {Area: "code_geo"}, tip: true}),
Plot.tickX(filtered_last.filter(function(x) {
return x.isd == "Births according to mother age"}), {x: "value", y: "indicator", stroke:"red"})
]
})
```
### Row
```{ojs}
//| title: Births by mother age - change over time
// ajouter plus grande valeur ou derniere
Plot.plot({
x:{label: "Year", domain: [2012, 2022], tickFormat: ""},
y:{label: "Difference to France (in %)"},
color: {
legend: true,
type: "categorical",
domain:["Under 20 years old",
"20-24 years old",
"25-29 years old",
"30-34 years old",
"35-39 years old",
"40 years old and above"]
},
marks : [
Plot.ruleY(filtered_c24, {x1: 2012, x2: 2022, y: 0, stroke: "grey"}),
Plot.lineY(filtered_c24, {x: "annee", y: "diff", stroke: "indicator", marker: "circle", tip: true})
]
})
```
# Indicators
## {.toolbar}
```{ojs}
// radio inputs
viewof isd = Inputs.radio(
data.map(d => d.isd),
{sort: true, unique: true, value: "Births according to mother age", label: "Indicator: "}
)
viewof indicator = Inputs.radio(
data.filter((x)=>{return x.isd == isd}).map(d =>d.indicator),
{sort: true, unique: true, value: "25-29 years old", label: "Dimension: "}
)
```
```{ojs}
//| output: false
data_grid_filtered = data_grid.filter(function(x){
return x.isd == isd && x.indicator == indicator
})
```
:::sidebar-note-right
Built by [Thomas Vroylandt](https://tvroylandt.github.io/personal/) at [Kantiles](https://kantiles.com/).
:::
## Row
### Column
```{ojs}
//| title: Grid cartogram of choosen indicator and dimension
// indicateur global sur un graph
Plot.plot({
height: 700,
width: 700,
axis: null,
color: {
type: "linear",
scheme: "gnbu"
},
marks: [
Plot.cell(data_grid_filtered, {x: "col", y: "row", fill: "value", inset: 0.5, tip: true}),
Plot.text(data_grid_filtered, {x: "col", y: "row", text: "code", fill: "black", dy: -5}),
Plot.text(data_grid_filtered, {x: "col", y: "row", text: "value", fill: "black", dy: 7, fillOpacity: 0.6})
]
})
```
# About
// faire un sub fichier pour voir si c'est possible
This dashboard is an exploration around some context indicators about births in France. It aims at showing some capabilities of [Observable JS](https://observablehq.com/) and [Quarto Dashboard](https://quarto.org/docs/dashboards/interactivity/observable.html) to display data in a reactive context. Data cleaning and wrangling was done in R by Kantiles. Code is available on [Github](https://github.com/kantiles/demo_isd).
Data comes from [France's Ministry of Health](https://data.drees.solidarites-sante.gouv.fr/explore/dataset/1520_indicateurs-de-sante-perinatale/information/).
Built by [Thomas Vroylandt](https://tvroylandt.github.io/personal/) at [Kantiles](https://kantiles.com/).
> This vizualisation hasn't been approved by the Ministry of Health and should only be use as a demonstrator. Please see the official dashboard on [VILAS](https://odin-dataviz-drees.sante.gouv.fr/digdash_dashboard_dataviz_drees/?defaultPage=vilas_Accueil&user=dataviz_sante&pass=dataviz_sante).