forked from flodebarre/covid_vaccination
-
Notifications
You must be signed in to change notification settings - Fork 0
/
livraisons.html
702 lines (548 loc) · 23.4 KB
/
livraisons.html
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="FD" />
<title>Livraisons - vaccination</title>
<script src="livraisons_files/header-attrs-2.7/header-attrs.js"></script>
<script src="livraisons_files/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="livraisons_files/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<script src="livraisons_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="livraisons_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="livraisons_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="livraisons_files/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="livraisons_files/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="livraisons_files/tocify-1.9.1/jquery.tocify.js"></script>
<script src="livraisons_files/navigation-1.1/tabsets.js"></script>
<script src="livraisons_files/navigation-1.1/codefolding.js"></script>
<link href="livraisons_files/highlightjs-9.12.0/default.css" rel="stylesheet" />
<script src="livraisons_files/highlightjs-9.12.0/highlight.js"></script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
pre code {
padding: 0;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "";
border: none;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-sm-12 col-md-4 col-lg-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-sm-12 col-md-8 col-lg-9">
<div id="header">
<div class="btn-group pull-right float-right">
<button type="button" class="btn btn-default btn-xs btn-secondary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>
<h1 class="title toc-ignore">Livraisons - vaccination</h1>
<h4 class="author">FD</h4>
</div>
<div id="initializations" class="section level1">
<h1>Initializations</h1>
</div>
<div id="load-data-and-clean-data" class="section level1">
<h1>Load data and clean data</h1>
<div id="livraisons" class="section level2">
<h2>Livraisons</h2>
<p>Source <a href="https://www.data.gouv.fr/en/datasets/donnees-relatives-aux-livraisons-de-vaccins-contre-la-covid-19/" class="uri">https://www.data.gouv.fr/en/datasets/donnees-relatives-aux-livraisons-de-vaccins-contre-la-covid-19/</a></p>
<pre class="r"><code>URL_livraisons <- "https://www.data.gouv.fr/en/datasets/r/c04da7da-be58-450e-bf3e-5993ce7796d9"
dataFile <- "data/livraisons.csv"
if(dlData){
download.file(URL_livraisons, dataFile)
}
dat.livraisons <- read.csv(dataFile, stringsAsFactors = FALSE)
head(dat.livraisons)
dat.livraisons</code></pre>
<pre class="r"><code>unique(dat.livraisons$type_de_vaccin)
dat.livraisons.AZ <- dat.livraisons[dat.livraisons$type_de_vaccin == "AstraZeneca", ]
dat.livraisons.Js <- dat.livraisons[dat.livraisons$type_de_vaccin == "Janssen", ]
dat.livraisons.Md <- dat.livraisons[dat.livraisons$type_de_vaccin == "Moderna", ]
dat.livraisons.Pz <- dat.livraisons[dat.livraisons$type_de_vaccin == "Pfizer", ]
plot(as.Date(dat.livraisons.Pz$date_fin_semaine), dat.livraisons.Pz$nb_doses, type = "h", frame.plot = FALSE,
xlab = "Date fin de semaine", ylab = "Nb doses",
main = "Quality check")
points(as.Date(dat.livraisons.AZ$date_fin_semaine), dat.livraisons.AZ$nb_doses, col = 2)
points(as.Date(dat.livraisons.Js$date_fin_semaine), dat.livraisons.Js$nb_doses, col = 3)
points(as.Date(dat.livraisons.Md$date_fin_semaine), dat.livraisons.Md$nb_doses, col = 4)
names(dat.livraisons.AZ)[2:4] <- c("typeAZ", "nb_ucd_AZ", "nb_doses_AZ")
names(dat.livraisons.Js)[2:4] <- c("typeJs", "nb_ucd_Js", "nb_doses_Js")
names(dat.livraisons.Md)[2:4] <- c("typeMd", "nb_ucd_Md", "nb_doses_Md")
names(dat.livraisons.Pz)[2:4] <- c("typePz", "nb_ucd_Pz", "nb_doses_Pz")
alltimes <- data.frame("date_fin_semaine" = sort(unique(dat.livraisons$date_fin_semaine)))
newdat <- data.frame(matrix(0, ncol = 4, nrow = 1))
names(newdat) <- names(dat.livraisons)
for(tv in unique(dat.livraisons$type_de_vaccin)){
print(tv)
subdat <- dat.livraisons[dat.livraisons$type_de_vaccin == tv, ]
subdat <- merge(alltimes, subdat, all = TRUE, by = "date_fin_semaine")
subdat$type_de_vaccin <- tv
# Find first
firstNonNA <- which(!is.na(subdat$nb_ucd))[1]
if(firstNonNA > 1){
subdat[1:(firstNonNA - 1), c("nb_ucd", "nb_doses")] <- 0
}
# Then loop on the lines -- maybe there's a more elegant way, but we have small enough datasets not to think this too hard
for(iline in firstNonNA:nrow(subdat)){
# If NA on the line, use value of the previous line
if(is.na(subdat[iline, "nb_ucd"])){
subdat[iline, c("nb_ucd", "nb_doses")] <- subdat[iline - 1, c("nb_ucd", "nb_doses")]
}
}
print(subdat)
newdat <- rbind(newdat, subdat)
}
# Remove first line put to create the dataframe
newdat <- newdat[-1, ]
dat.livraisons2 <- newdat
# Quality check
cols <- 1:4
names(cols) <- unique(dat.livraisons$type_de_vaccin)
points(as.Date(dat.livraisons2$date_fin_semaine),
dat.livraisons2$nb_doses,
col = cols[dat.livraisons2$type_de_vaccin], pch = 4)</code></pre>
<pre class="r"><code>doses.livraisons.total <- aggregate(dat.livraisons2$nb_doses, by = list("date_fin_semaine" = dat.livraisons2$date_fin_semaine), FUN = sum)
names(doses.livraisons.total)[2] <- "nb_doses"</code></pre>
</div>
<div id="personnes-vaccinees" class="section level2">
<h2>Personnes vaccinees</h2>
<p>Source <a href="https://www.data.gouv.fr/fr/datasets/donnees-relatives-aux-personnes-vaccinees-contre-la-covid-19-1/" class="uri">https://www.data.gouv.fr/fr/datasets/donnees-relatives-aux-personnes-vaccinees-contre-la-covid-19-1/</a></p>
<blockquote>
<p>Fichiers avec le nombre de personnes ayant reçu au moins une dose ou deux doses, par vaccin, arrêté à la dernière date disponible :</p>
<p>vacsi-tot-v-fra-YYYY-MM-DD-HHhmm.csv (échelle nationale)</p>
<p>Fichiers avec le nombre de personnes ayant reçu au moins une dose ou complètement vaccinées, arrêté à la dernière date disponible :</p>
<p>vacsi-tot-fra-YYYY-MM-DD-HHhmm.csv (échelle nationale)</p>
<p>0 : Tous vaccins<br />
1 : COMIRNATY Pfizer/BioNTech<br />
2 : Moderna<br />
3 : AstraZeneka<br />
4 : Janssen</p>
</blockquote>
<pre class="r"><code>URL_v12 <- "https://www.data.gouv.fr/fr/datasets/r/b273cf3b-e9de-437c-af55-eda5979e92fc"
dataFile <- "data/vaccin_12doses.csv"
if(dlData){
download.file(URL_v12, dataFile)
}
dat.vaccin12 <- read.csv(dataFile, stringsAsFactors = FALSE, sep = ";")
head(dat.vaccin12)
dat.vaccins <- dat.vaccin12[which(dat.vaccin12$vaccin != 0), ]
dic.typeVaccin <- c("Pfizer", "Moderna", "AstraZeneca", "Janssen")
names(dic.typeVaccin) <- as.character(1:4)
dat.vaccins$typeVaccin <- dic.typeVaccin[dat.vaccins$vaccin]
# Subselect tous vaccins
dat.vaccin12 <- dat.vaccin12[which(dat.vaccin12$vaccin == 0), ]
# Number of doses
dat.vaccin12$n_doses <- dat.vaccin12$n_dose1 + dat.vaccin12$n_dose2
dat.vaccin12$n_cum_doses <- cumsum(dat.vaccin12$n_doses)</code></pre>
<pre class="r"><code># This is actually not needed, but I am keeping it for legacy
URL_v1c <- "https://www.data.gouv.fr/fr/datasets/r/efe23314-67c4-45d3-89a2-3faef82fae90"
dataFile <- "data/vaccin_1cdoses.csv"
if(dlData){
download.file(URL_v1c, dataFile)
}
dat.vaccin1c <- read.csv(dataFile, stringsAsFactors = FALSE, sep = ";")
head(dat.vaccin1c)</code></pre>
<pre class="r"><code>par(las = 1)
plot(as.Date(dat.vaccin12$jour), dat.vaccin12$n_cum_dose1, type = "l",
xlab = "date", ylab = "number individuals")
lines(as.Date(dat.vaccin12$jour), dat.vaccin12$n_cum_dose2, type = "l", col = 2)
lines(as.Date(dat.vaccin1c$jour), dat.vaccin1c$n_cum_dose1, type = "l", col = 3, lty = 2)
lines(as.Date(dat.vaccin1c$jour), dat.vaccin1c$n_cum_complet, type = "l", col = 4, lty = 1)
legend("topleft", col = c(1, 2, 3, 4), lty = c(1, 1, 2, 1), legend = c("1 dose au moins", "2 doses", "1 dose au moins", "complet"), bty = "n")</code></pre>
<p>We can deduce the number of people with complete vaccination after one dose (dose1_complet) and one dose and incomplete vaccination (but actually we do not need this for vaccine doses)</p>
<pre class="r"><code># Just keeping this for legacy
# Quality checks
for(col in c("n_dose1", "n_cum_dose1")){
print(all(dat.vaccin12[, col] == dat.vaccin1c[, col]))
}
dat.vaccin <- merge(dat.vaccin12, dat.vaccin1c[, c("jour", "n_complet", "n_cum_complet")], by = "jour")
# Other quality checks (cum sums)
all(dat.vaccin$n_cum_dose1 == cumsum(dat.vaccin$n_dose1))
all(dat.vaccin$n_cum_dose2 == cumsum(dat.vaccin$n_dose2))
all(dat.vaccin$n_cum_complet == cumsum(dat.vaccin$n_complet))
# 1 dose and complete
dat.vaccin$n_dose1complet <- dat.vaccin$n_complet - dat.vaccin$n_dose2
dat.vaccin$n_cum_dose1complet <- cumsum(dat.vaccin$n_dose1complet)
# 1 dose and incomplete
dat.vaccin$n_dose1incomplet <- dat.vaccin$n_dose1 - dat.vaccin$n_complet
dat.vaccin$n_cum_dose1incomplet <- cumsum(dat.vaccin$n_dose1incomplet)
# Quality check
all(dat.vaccin$n_cum_dose1 == dat.vaccin$n_cum_dose2 + dat.vaccin$n_cum_dose1complet + dat.vaccin$n_cum_dose1incomplet)</code></pre>
<div id="homogenize-datasets" class="section level3">
<h3>Homogenize datasets</h3>
<p>Function to add NA lines or fill in with info from previous date</p>
<pre class="r"><code># All dates
xx <- sort(unique(dat.vaccin12$jour))
fillTable <- function(mat, x = xx){
# mat is the matrix with same columns as dat.vaccins,
# x is the full vector of dates;
# the dates in the data must be included in x
# Check that dates are sorted
check1 <- all(mat[order(mat$jour), "jour"] == mat$jour)
if(!check1) stop("make sure to order dates")
# Check that no duplicated date
if(any(duplicated(mat$jour))) stop("There are duplicated dates (maybe multiple vaccine types?)")
# Check that all dates are included in x
if(!all(is.element(unique(mat$jour), x))) stop("x does not contain all the dates of the dataset")
# New dataset will all the dates that we want
newmat <- merge(data.frame(jour = x), mat, by = "jour", all = TRUE) # Fill with NA the missing dates
# Find first non NA value, fill previous lines with 0
firstNonNA <- which(!is.na(newmat$n_dose1))[1]
if(firstNonNA > 1){ # If there are lines before
newmat[1:(firstNonNA - 1), c("n_dose1", "n_dose2", "n_cum_dose1", "n_cum_dose2")] <- 0
}
# Then loop on the lines -- maybe there's a more elegant way, but we have small enough datasets not to think this too hard
for(iline in firstNonNA:nrow(newdat)){
# If NA on the line, use value of the previous line
if(is.na(newmat[iline, "n_dose1"])){
newmat[iline, -c("jour")] <- newmat[iline - 1, -c("jour")]
}
}
newmat
}
# Compute them for each vaccine type
dat.Pz <- fillTable(dat.vaccins[dat.vaccins$typeVaccin == "Pfizer", ])
dat.Md <- fillTable(dat.vaccins[dat.vaccins$typeVaccin == "Moderna", ])
dat.AZ <- fillTable(dat.vaccins[dat.vaccins$typeVaccin == "AstraZeneca", ])
dat.Js <- fillTable(dat.vaccins[dat.vaccins$typeVaccin == "Janssen", ])
# Re-bind the dataset
dat.vaccins <- rbind(dat.Pz, dat.Md, dat.AZ, dat.Js)
names(dat.vaccins) <- names(dat.Pz)
# Sum first dose and second dose to have the total number of injected doses
dat.vaccins$n_cum <- dat.vaccins$n_cum_dose1 + dat.vaccins$n_cum_dose2</code></pre>
</div>
</div>
</div>
<div id="combine-datasets" class="section level1">
<h1>Combine datasets</h1>
<div id="all-vaccines" class="section level2">
<h2>All vaccines</h2>
<pre class="r"><code>col_injections <- "#2a9d8f"
col_doses <- "#e76f51"
lwdd <- 2
yy <- pretty(seq(0, max(doses.livraisons.total$nb_doses), 5))/10^6
# yy
xx <- seq(as.Date("2020-12-01"), as.Date("2021-08-01"), by = "month")
# xx
par(mar = c(4.5, 4, 2, 4), las = 1)
plot(as.Date(doses.livraisons.total$date_fin_semaine), doses.livraisons.total$nb_doses/(10^6), type = "n",
xlab = "",
ylab = "",
col = col_doses, lwd = lwdd,
ylim = range(yy),
yaxs = "i", xaxs = "i",
frame.plot = FALSE)
for(i in seq(0, max(yy), by = 10)) abline(h = i, col = gray(0.9))
legend("topleft", col = c(col_doses, col_injections), lty = 1, legend = c("Total doses livrées", "Total doses injectées"), lwd = lwdd, title = "En millions:", box.lwd = 0.0, inset = c(0.02, 0), bg = gray(1, 0.5), bty = "o")
axis(1, at = xx, labels = format(xx, "%b"))
axis(2)
lines(as.Date(doses.livraisons.total$date_fin_semaine), doses.livraisons.total$nb_doses/(10^6), col = col_doses, lwd = lwdd)
lines(as.Date(dat.vaccin12$jour), dat.vaccin12$n_cum_doses/10^6, type = "l", col = col_injections, lwd = lwdd)
xmax <- max(c(as.Date(dat.vaccin12$jour), as.Date(doses.livraisons.total$date_fin_semaine)))
par(xpd = TRUE)
text(rep(as.Date(xmax), 2), c(max(dat.vaccin12$n_cum_doses/10^6), max(doses.livraisons.total$nb_doses/(10^6))),
labels = paste(round(c(max(dat.vaccin12$n_cum_doses/10^6), max(doses.livraisons.total$nb_doses/(10^6))), 1), "Mio"),
col = c(col_injections, col_doses), adj = c(0, 0.5))
par(xpd = FALSE)
mtext(side = 1, adj = 0, text = paste0(format(Sys.time(), "%Y-%m-%d"), " | Données :
- Livraisons https://www.data.gouv.fr/en/datasets/donnees-relatives-aux-livraisons-de-vaccins-contre-la-covid-19/
- Injections https://www.data.gouv.fr/fr/datasets/donnees-relatives-aux-personnes-vaccinees-contre-la-covid-19-1/"), cex = 0.6, col = gray(0.5), line = 3)</code></pre>
<p><img src="livraisons_files/figure-html/unnamed-chunk-9-1.png" width="672" /></p>
</div>
<div id="by-type-of-vaccine" class="section level2">
<h2>By type of vaccine</h2>
<div id="livraisons-et-injections" class="section level3">
<h3>Livraisons et injections</h3>
<pre class="r"><code># Define colors of vaccine types
colType <- c("blue", "red", "orange", rgb(0, 0.6, 0))
names(colType) <- c("Pfizer", "Moderna", "AstraZeneca", "Janssen")
# Define pch of vaccine types
pchType <- 0:3
names(pchType) <- names(colType)
# Line width
lwdd <- 2
# Denominator for scale
# (1 for full value, 10^6 if by million)
denom <- 10^6
par(las = 1)
layout(matrix(1:4, ncol = 2))
# For each vaccine type
for(typ in names(colType)){
# Subsets of the data with this type
subliv <- dat.livraisons2[which(dat.livraisons2$type_de_vaccin == typ), ]
subdoses <- dat.vaccins[dat.vaccins$typeVaccin == typ, ]
# Set ymax value (same scale for smaller values)
ymax <- 1.05 * max(subliv$nb_doses)
if(ymax < 12*10^6) ymax <- 12*10^6
par(mar = c(2, 3, 2, 2),
mgp = c(1.5, 0.25, 0), tck = -0.015, xpd = TRUE,
las = 1)
plot(as.Date(subliv$date_fin_semaine), subliv$nb_doses/denom,
col = colType[typ], pch = pchType[typ],
type = "o",
ylim = c(0, ymax/denom),
xlab = "", ylab = "en millions", main = typ, yaxs = "i")
legend("topleft", col = colType[typ], pch = c(pchType[typ], NA), lty = 1, lwd = c(1, lwdd), legend = c("livraisons", "injections"), bty = "n", inset = c(0.01, 0))
lines(as.Date(subdoses$jour), subdoses$n_cum/denom, col = colType[typ], lwd = lwdd, pch = pchType[typ])
axis(4)
par(xpd = FALSE)
}</code></pre>
<p><img src="livraisons_files/figure-html/unnamed-chunk-10-1.png" width="672" /></p>
</div>
<div id="ecart-entre-livraisons-et-injections" class="section level3">
<h3>Ecart entre livraisons et injections</h3>
<pre class="r"><code># Combine the two datasets to make sure we get the same dates
dat.combined <- merge(dat.livraisons2, dat.vaccins, by.x = c("date_fin_semaine", "type_de_vaccin"), by.y = c("jour", "typeVaccin"), all = TRUE)
# Compute remaining number of doses
dat.combined$remaining <- dat.combined$nb_doses - dat.combined$n_cum
par(mfrow = c(1, 1), xpd = FALSE,
mgp = c(1.25, 0.25, 0), tck = -0.01,
mar = c(4, 3, 3, 3), las = 1)
plot(as.Date(dat.combined$date_fin_semaine), dat.combined$remaining/denom, col = colType[dat.combined$type_de_vaccin], type = "n", yaxs = "i",
xlab = "", ylab = "en millions",
axes = FALSE, main = "Doses disponibles")
mtext("date fin semaine", side = 1, line = 3)
# x axis
xx <- sort(unique(dat.livraisons2$date_fin_semaine))
if(max(xx) > max(dat.vaccins$jour)){xx <- xx[1:(length(xx)-1)]}
axis(1, at = as.Date(xx), labels = format.Date(xx, "%Y-%m-%d"), las = 3, cex.axis = 0.6)
axis(2)
axis(4)
# Graduations
for(i in seq(0, 5, by = 0.5)){
abline(h = i, col = gray(0.9))
}
cexx <- 0.75 # marker size
par(xpd = TRUE)
for(typ in names(colType)){
# Subset of the data for this vaccine type
subdat <- dat.combined[dat.combined$type_de_vaccin == typ, ]
# Remove NAs
# (injections by day, livraisons by week)
# (necessary to plot the line between markers)
subdat <- subdat[!is.na(subdat$remaining/denom), ]
points(as.Date(subdat$date_fin_semaine), subdat$remaining/denom, type = "o", lty = 1, col = colType[typ], pch = pchType[typ], cex = cexx)
}
legend("topleft", inset = c(0.01, 0), box.lwd = 0, legend = names(colType), lty = 1, col = colType, pch = pchType, pt.cex = cexx)</code></pre>
<p><img src="livraisons_files/figure-html/unnamed-chunk-11-1.png" width="672" /></p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
window.initializeCodeFolding("hide" === "show");
});
</script>
<script>
$(document).ready(function () {
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>