-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDescription_CCCSL_v2.Rmd
821 lines (661 loc) · 27.8 KB
/
Description_CCCSL_v2.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
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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
---
title: '**Description of the CCCSL dataset - Suppporting Information**'
author: "Amélie Desvars-Larrive, David Garcia"
output:
pdf_document: default
date: "12/07/2020"
---
```{r, echo=FALSE, message=FALSE, results='hide', warning = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(knitr)
library(ggplot2)
library(tidyr)
library(lubridate)
library(kableExtra)
```
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4, results='hide'}
# For an updated version of the dataset, use the dataset from the CCCSL Github repository: https://github.com/amel-github/covid19-interventionmeasures
# See http://covid19-interventions.com/
# Import static version of the data on governmental NPIs from Github
measures1 <- read.csv("https://raw.githubusercontent.com/amel-github/CCCSL-Codes/master/COVID19_non-pharmaceutical-interventions_version2_utf8_static_2020-07-12.csv", colClasses=c("Country"="character"))
# If you download the dataset, the .Rmd file and the dataset need to be in the same folder (change file name if another version is used)
#measures1 <- read.csv("COVID19_non-pharmaceutical-interventions_version2_utf8_static_2020-07-12.csv", colClasses=c("Country"="character"))
# For using live data
#measures1 <- read.csv("https://raw.githubusercontent.com/amel-github/covid19-interventionmeasures/master/COVID19_non-pharmaceutical-interventions_version2_utf8.csv", colClasses=c("Country"="character"))
# Date into class date data
measures1$Date <- as.Date (measures1$Date , format = "%Y-%m-%d")
# change country names to be the same as the in Johns Hopkins University CSSE (for data usage)
measures1$Country[measures1$Country=="Taiwan"]<- "Taiwan*"
measures1$Country[measures1$Country=="South Korea"]<- "Korea, South"
measures1$Country[measures1$Country=="Czech Republic"]<- "Czechia"
measures1$Country[measures1$Country=="Republic of Ireland"]<- "Ireland"
measures1$Country[measures1$Country=="United States of America"]<- "US"
# Number of measures in the Diamond Princess cruise ship
DP <- nrow(measures1 %>% filter(Country == "Diamond Princess"))
# Remove the Diamond Princess from graphs and tables
measures <- measures1 %>% filter (Country != "Diamond Princess")
# Subsets for each L1-code category
L1_1 <- measures %>% filter(Measure_L1 == "Case identification, contact tracing and related measures")
L1_2 <- measures %>% filter(Measure_L1 == "Environmental measures")
L1_3 <- measures %>% filter(Measure_L1 == "Healthcare and public health capacity")
L1_4 <- measures %>% filter(Measure_L1 == "Resource allocation")
L1_5 <- measures %>% filter(Measure_L1 == "Returning to normal life")
L1_6 <- measures %>% filter(Measure_L1 == "Risk communication")
L1_7 <- measures %>% filter(Measure_L1 == "Social distancing")
L1_8 <- measures %>% filter(Measure_L1 == "Travel restriction")
```
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4, results='hide'}
# number of records per region of the world
asia <- c("China" , "Indonesia", "Kuwait", "Malaysia","Singapore","Korea, South","Syria","Taiwan*","Thailand","Japan" ,"Kazakhstan","India")
europe <- c("Albania" ,"Austria","Belgium", "Italy" , "Croatia","Czechia","Denmark","Estonia","Finland","France","Germany","Iceland",
"Liechtenstein" ,"Lithuania", "Montenegro","Netherlands","Norway", "Poland","Portugal","Ireland","Romania", "Serbia","Slovakia","Spain", "Sweden", "Switzerland","Greece","Kosovo","Hungary","Bosnia and Herzegovina", "United Kingdom" ,"North Macedonia", "Slovenia")
north.america <- c("Canada", "US")
south.america <- c("Ecuador","Mexico","Honduras" ,"Brazil","El Salvador")
oceania <- c("New Zealand" )
africa <- c("Ghana", "Mauritius", "Senegal")
# number of records per country
count.country <- aggregate(measures, by=list(measures$Country), FUN=length)
```
The CCCSL dataset includes information for `r nrow(measures1)` NPIs implemented between `r min(measures1$Date)` and `r max(measures1$Date)`.
The CCCSL dataset presents data for `r length(unique(measures$Country))` countries, including `r length(europe)` European countries, `r length(asia)` Asian countries, `r length(south.america)` South American, `r length(north.america)` North American countries, `r length((oceania))` Oceanian country, `r length((africa))` African countries, and the Diamond Princess cruise ship.
The median number of NPIs implemented by the governments to mitigate the burden of COVID-19 is `r median(count.country$Country)` (min. = `r min(count.country$Country)`; max. = `r max(count.country$Country)`).
*Note: Version 2 of the CCCSL dataset presents a consolidated coding scheme. Data on Poland, Senegal, and Ghana have been added as well as data for 24 states of the USA.*
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
## plot of the number of the NPIs implemented worldwide over calendar time
plot1 <- ggplot(measures, aes(x = Date, fill = Measure_L1)) +
geom_bar(position = "stack") + theme_minimal() +
labs(title = "Implementation of interventions over calendar time",
x = "Date",
y = "Number of interventions")+
scale_x_date(name = 'Date', date_breaks = '7 days',
date_labels = '%d-%m-%y')+
theme(axis.text.x = element_text(size=8, angle=45, hjust = 1))+
theme(axis.ticks.x = element_line(colour = "black", size = 1))+
guides(fill=guide_legend(title=""))+
theme(legend.title = element_blank()) +
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
```
```{r plot1, echo=FALSE}
plot(plot1, caption = "Histogram of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme and time of implementation over calendar time (Diamond Princess cruise ship excluded).")
```
```{r echo=FALSE, fig.height=4, fig.width=8, message=FALSE}
# Summary of the number of measures for each L1-, L2-, and L3-code category of NPI for each country
prop.table.L1 <- prop.table(table(measures$Measure_L1))
value.L1 <- as.vector(round(prop.table.L1, 2))
value.L2 <- as.vector(table(measures$Measure_L1))
table0 <- cbind.data.frame(names(prop.table.L1 ), value.L2, value.L1 )
rownames(table0) <- NULL
# number of unique measures for each code category
uniqueL1 <- nrow(unique(L1_1[,c("Measure_L1","Measure_L2")]))
uniqueL2 <- nrow(unique(L1_2[,c("Measure_L1","Measure_L2")]))
uniqueL3 <- nrow(unique(L1_3[,c("Measure_L1","Measure_L2")]))
uniqueL4 <- nrow(unique(L1_4[,c("Measure_L1","Measure_L2")]))
uniqueL5 <- nrow(unique(L1_5[,c("Measure_L1","Measure_L2")]))
uniqueL6 <- nrow(unique(L1_6[,c("Measure_L1","Measure_L2")]))
uniqueL7 <- nrow(unique(L1_7[,c("Measure_L1","Measure_L2")]))
uniqueL8 <- nrow(unique(L1_8[,c("Measure_L1","Measure_L2")]))
colnames (table0) <- c("Theme (L1)", "Number of records", "Frequency")
kable(table0, booktabs = T,
caption = "Summary of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme (Diamond Princess cruise ship excluded).", format="latex") %>%
kable_styling(latex_options="scale_down")
```
```{r echo=FALSE, fig.height=4, fig.width=8, message=FALSE}
# Top 20 most frequent L2-code categories in the CCCSL
rank.l2 <- aggregate( Country~ Measure_L2, data = measures, FUN = length)
rank.l2.2 <- rank.l2 %>%
arrange(Country)
prop.L2 <- (rank.l2.2[,2])/sum(rank.l2.2[,2])
prop.L2.1 <- cbind.data.frame(rank.l2.2, round(prop.L2,2))
table2 <- prop.L2.1 [order(-prop.L2.1$Country ),]
table2.f <- table2[c(1:20),]
colnames(table2.f) <- c("Category (L2)", "Number of record", "Frequency")
rownames(table2.f) <- NULL
kable(table2.f, booktabs = T,
caption = "Top 20 most frequent NPIs recorded in the CCCSL at level 2 (categories) of the coding scheme (Diamond Princess cruise ship excluded).")
```
\pagebreak
# Country-based summaries of NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme.
```{r echo=FALSE, fig.height=4, fig.width=8, message=FALSE}
# summary of ALL measures per country
m_L1 <- sort(unique(measures1$Measure_L1))
measures1 %>%
group_by(Country) %>%
summarise(case.id.cnt= sum(Measure_L1==m_L1[1]) , envir.id.cnt= sum(Measure_L1==m_L1[2]) , healthcare.capacity.cnt= sum(Measure_L1==m_L1[3]),resource.allocation.cnt= sum(Measure_L1==m_L1[4]) ,returen.id =sum(Measure_L1==m_L1[5]) ,risk.communication.cnt= sum(Measure_L1==m_L1[6]),social.distancing.cnt= sum(Measure_L1==m_L1[7]) , travel.restriction.cnt= sum(Measure_L1==m_L1[8]) ) ->L1count
L1count$total <- rowSums(L1count[,2:9])
colnames(L1count) <- c("Country", "Case identification, contact tracing and related measures", "Environmental measures","Healthcare and public health capacity", "Resource allocation", "Returning to normal life","Risk communication", "Social distancing","Travel restriction", "Total")
kable(L1count, booktabs = T,
caption = "Summary per country of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme.", format="latex") %>%
kable_styling(latex_options="scale_down")
```
## Overview of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme over the epidemic age (t0 = 10 confirmed cases)
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4, results='hide'}
# Import data on number of cases, recovered, and deaths
# We use the case data from the Johns Hopkins repository: https://github.com/CSSEGISandData/COVID-19
# See https://linkinghub.elsevier.com/retrieve/pii/S1473309920301201
confirmeddf <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv", stringsAsFactors = F, colClasses=c("Country.Region"="character"))
deathsdf <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv", stringsAsFactors = F, colClasses=c("Country.Region"="character"))
recovereddf <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv", stringsAsFactors = F, colClasses=c("Country.Region"="character"))
# List of countries to iterate
countries <- unique(c(confirmeddf$Country.Region, deathsdf$Country.Region, recovereddf$Country.Region))
# We convert the data frame from wide to long format
ldf <- data.frame(country=NULL, date=NULL, confirmed=NULL, deaths=NULL, recovered=NULL)
for (country in countries)
{
# The first four columns contain the name of the country, location, etc. The time series win wide format starts from the fifth.
confirmeddf %>%
filter(Country.Region == country) %>%
summarise_at(5:ncol(confirmeddf), sum) -> confirmedcounts
dates <- names(confirmeddf)[5:ncol(confirmeddf)]
# Dates are in a weird format, we convert them for R
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
confirmeddfsel <- data.frame(confirmed = as.numeric(confirmedcounts), date=dates)
# We repeat the above process for deaths and recovered time series
deathsdf %>%
filter(Country.Region == country) %>%
summarise_at(5:ncol(deathsdf), sum) -> deathscounts
dates <- names(deathsdf)[5:ncol(deathsdf)]
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
deathsdfsel <- data.frame(deaths = as.numeric(deathscounts), date=dates)
recovereddf %>%
filter(Country.Region == country) %>%
summarise_at(5:ncol(recovereddf), sum) -> recoveredcounts
dates <- names(recovereddf)[5:ncol(recovereddf)]
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
recovereddfsel <- data.frame(recovered = as.numeric(recoveredcounts), date=dates)
# inner_joins map all data by date so the long format has a column for confirmed, another for deaths, and a third one for recovered
newdf <- inner_join(confirmeddfsel, deathsdfsel)
newdf <- inner_join(newdf, recovereddfsel)
# We add the country name and include this country in the full data frame
newdf$Country = country
ldf <- rbind(ldf, newdf)
}
```
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
# create t0 of epidemic age for each country t0 = day with 10 cases
ldf %>%
group_by(Country) %>%
filter(confirmed >=10) %>%
summarise(edate = min(date)) -> ctry_edate
ldf %>%
select(Country) %>%
unique() -> ctry_names
measures %>%
left_join(ctry_edate, by = "Country") %>%
filter(!is.na(edate)) %>%
mutate(Date = as.numeric(Date - edate)) %>%
left_join(ctry_names, by = "Country") %>%
select(Country, Date, edate, Measure_L1) -> edates
```
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
# plot number of measures function of epidemic age
lab_x <- "Epidemic age (t0 = 10 confirmed cases)"
plot2 <- ggplot(edates, aes(x = Date, fill = Measure_L1)) +
geom_bar(position = "stack") + theme_minimal() +
labs(title = "Implementation of interventions over epidemic age",
x = lab_x,
y = "Number of interventions")+
theme(legend.title = element_blank()) +
theme(axis.text.x = element_text(size=10)) +
theme(axis.title.y = element_text( size=10))+
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
```
```{r plot2, echo=FALSE}
plot(plot2, caption = "NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme and time of implementation over epidemic age and all countries (t0 = day when 10 cases were reported)")
```
```{r echo=FALSE, fig.height=4, fig.width=8, message=FALSE}
#identify range of dates for each L1-code category: timeline and responsiveness
test <- edates %>%
group_by(Date, Measure_L1) %>%
summarise(
count = n()
) %>%
ungroup() %>%
arrange(Measure_L1, Date) %>%
group_by(Measure_L1) %>%
mutate(count = cumsum(count)) %>%
complete(Date = min(edates$Date):max(edates$Date)) %>%
fill(count) %>%
replace_na(list(count = 0))
test1 <- aggregate(count ~ Date + Measure_L1, data = test, FUN = sum)
test1 %>%
filter (Measure_L1 == "Case identification, contact tracing and related measures") %>%
filter (count != 0) -> case.id
test1 %>%
filter (Measure_L1 == "Environmental measures") %>%
filter (count != 0) -> envir.id
test1 %>%
filter (Measure_L1 == "Healthcare and public health capacity") %>%
filter (count != 0) ->health.id
test1 %>%
filter (Measure_L1 == "Resource allocation") %>%
filter (count != 0) -> ress.id
test1 %>%
filter (Measure_L1 == "Returning to normal life") %>%
filter (count != 0) -> return.id
test1 %>%
filter (Measure_L1 == "Risk communication") %>%
filter (count != 0) -> risk.id
test1 %>%
filter (Measure_L1 == "Social distancing") %>%
filter (count != 0) -> socd.id
test1 %>%
filter (Measure_L1 == "Travel restriction") %>%
filter (count != 0) -> trav.id
table01 <- rbind.data.frame(summary(case.id$Date), summary(envir.id$Date),summary(health.id$Date),summary(ress.id$Date), summary(return.id$Date), summary(risk.id$Date), summary(socd.id$Date),summary(trav.id$Date) )
table1 <- cbind (unique(test1$Measure_L1), table01)
colnames(table1) <- c("L1-code category","Min. epi-date", "1st Qu. epi-date" ,"Median epi-date","Mean epi-date","3rd Qu. epi-date","Max. epi-date")
kable(table1, booktabs = T,
caption = "Characterization of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme: summary of the timeline of implementation over all countries.", format="latex") %>%
kable_styling(latex_options="scale_down")
```
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
# Stacked area chart of the L1-code categories
plot3 <- edates %>%
group_by(Date, Measure_L1) %>%
summarise(
count = n()
) %>%
ungroup() %>%
arrange(Measure_L1, Date) %>%
group_by(Measure_L1) %>%
mutate(count = cumsum(count)) %>%
complete(Date = min(edates$Date):max(edates$Date)) %>%
fill(count) %>%
replace_na(list(count = 0)) %>%
ggplot(aes(x = Date, fill = Measure_L1, y = count)) +
theme_minimal() + labs(
x = lab_x,
y = "Percentage share of all interventions at event date",
fill = "Measure_L1"
) +
geom_area(position = "fill") +
theme(axis.text.x = element_text(size=10)) +
theme(axis.title.y = element_text( size=10))+
scale_y_continuous(labels = scales::percent)+
theme(legend.title = element_blank())+
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
```
```{r plot3, echo=FALSE}
plot(plot3, caption = "Stacked area chart of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme. Time is in epidemic age (t0 = day when 10 cases were reported).")
```
## Country-based overview of the NPIs recorded in the CCCSL at level 1 (themes) of the coding scheme over the epidemic age (t0 = 10 confirmed cases) - All countries
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
lab_x <- "Epidemic age (t0 = 10 confirmed cases)"
plot.country <- function (name.country)
{
edates [edates$Country==name.country,] %>%
group_by(Date, Measure_L1) %>%
summarise(
count = n()
) %>%
ungroup() %>%
arrange(Measure_L1, Date) %>%
group_by(Measure_L1) %>%
mutate(count = cumsum(count)) %>%
complete(Date = min(edates$Date):max(edates$Date)) %>%
fill(count) %>%
replace_na(list(count = 0)) %>%
ggplot(aes(x = Date, fill = Measure_L1, y = count)) +
theme_minimal() + labs(
x = lab_x,
y = "Percentage share of all interventions at event date",
fill = ""
) +
geom_area(position = "fill") +
scale_y_continuous(labels = scales::percent)+
labs(title=name.country)+
theme(legend.title = element_blank())+
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
}
```
## Asia
### Hong Kong, China
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4, warning=FALSE}
## need to create HK data set for cases
regions <- unique(c(confirmeddf$Province.State, deathsdf$Province.State, recovereddf$Province.State))
ldf2 <- data.frame(region=NULL, date=NULL, confirmed=NULL, deaths=NULL, recovered=NULL)
for (region in regions)
{
# The first four columns contain the name of the country, location, etc. The time series win wide format starts from the fifth.
confirmeddf %>%
filter(Province.State == region) %>%
summarise_at(5:ncol(confirmeddf), sum) -> confirmedcounts
dates <- names(confirmeddf)[5:ncol(confirmeddf)]
# Dates are in a weird format, we convert them for R
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
confirmeddfsel <- data.frame(confirmed = as.numeric(confirmedcounts), date=dates)
# We repeat the above process for deaths and recovered time series
deathsdf %>%
filter(Province.State == region) %>%
summarise_at(5:ncol(deathsdf), sum) -> deathscounts
dates <- names(deathsdf)[5:ncol(deathsdf)]
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
deathsdfsel <- data.frame(deaths = as.numeric(deathscounts), date=dates)
recovereddf %>%
filter(Province.State == region) %>%
summarise_at(5:ncol(recovereddf), sum) -> recoveredcounts
dates <- names(recovereddf)[5:ncol(recovereddf)]
dates <- as.Date(gsub("\\.", "-", sub(".", "", dates)), format = "%m-%d-%y")
recovereddfsel <- data.frame(recovered = as.numeric(recoveredcounts), date=dates)
# inner_joins map all data by date so the long format has a column for confirmed, another for deaths, and a third one for recovered
newdf <- inner_join(confirmeddfsel, deathsdfsel)
newdf <- inner_join(newdf, recovereddfsel)
# We add the country name and include this country in the full data frame
newdf$Country = region
ldf2 <- rbind(ldf2, newdf)
}
ldf2 %>%
group_by(Country) %>%
filter(confirmed >= 10) %>%
summarise(edate = min(date)) -> ctry_edate2
ldf2 %>%
select(Country) %>%
unique() -> ctry_names2
# measures
measures %>%
left_join(ctry_edate2, by = c("Region" = "Country")) %>%
filter(!is.na(edate)) %>%
mutate(Date = as.numeric(Date - edate)) %>%
left_join(ctry_names, by = "Country") %>%
select(Region, Country, Date, edate, Measure_L1) -> edates2
edates2 [edates2$Region=="Hong Kong",] %>%
group_by(Date, Measure_L1) %>%
summarise(
count = n()
) %>%
ungroup() %>%
arrange(Measure_L1, Date) %>%
group_by(Measure_L1) %>%
mutate(count = cumsum(count)) %>%
complete(Date = min(edates2$Date):max(edates2$Date)) %>%
fill(count) %>%
replace_na(list(count = 0)) %>%
ggplot(aes(x = Date, fill = Measure_L1, y = count)) +
theme_minimal() + labs(
x = lab_x,
y = "Percentage share of all interventions at event date",
fill = ""
) +
geom_area(position = "fill") +
scale_y_continuous(labels = scales::percent)+
labs(title="Hong Kong")+
theme(legend.title = element_blank())+
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
```
### India
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "India")
```
### Indonesia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Indonesia")
```
### Japan
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Japan")
```
### Kazakhstan
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Kazakhstan")
```
### Kuwait
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Kuwait")
```
### Malaysia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Malaysia")
```
### Singapore
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Singapore")
```
### South Korea
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Korea, South")
```
### Taiwan
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Taiwan*")
```
### Thailand
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Thailand")
```
### Syria
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Syria")
```
## Europe
### Albania
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Albania")
```
### Austria
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Austria")
```
### Belgium
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Belgium")
```
### Bosnia and Herzegovina
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Bosnia and Herzegovina")
```
### Croatia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Croatia")
```
### Czech Republic
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Czechia")
```
### Denmark
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Denmark")
```
### Estonia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Estonia")
```
### Finland
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Finland")
```
### France (metropole)
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "France")
```
### Germany
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Germany")
```
### Greece
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Greece")
```
### Hungary
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Hungary")
```
### Iceland
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Iceland")
```
### Ireland
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Ireland")
```
### Italy
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Italy")
```
### Kosovo
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Kosovo")
```
### Liechtenstein
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Liechtenstein")
```
### Lithuania
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Lithuania")
```
### Montenegro
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Montenegro")
```
### Netherlands
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Netherlands")
```
### North Macedonia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "North Macedonia")
```
### Norway
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Norway")
```
### Poland
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Poland")
```
### Portugal
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Portugal")
```
### Romania
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Romania")
```
### Serbia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Serbia")
```
### Slovakia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Slovakia")
```
### Slovenia
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Slovenia")
```
### Spain
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Spain")
```
### Sweden
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Sweden")
```
### Switzerland
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Switzerland")
```
### United Kingdom
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "United Kingdom")
```
## North America
### Canada
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Canada")
```
### United States of America
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ("US")
```
## South America
### Brazil
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Brazil")
```
### Ecuador
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Ecuador")
```
### El Salvador
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "El Salvador")
```
### Honduras
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Honduras")
```
### Mexico
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Mexico")
```
## Oceania
### New Zealand
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "New Zealand")
```
## Africa
### Ghana
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Ghana")
```
### Mauritius
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Mauritius")
```
### Senegal
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
plot.country ( "Senegal")
```
## Diamond Princess cruise ship
```{r, echo=FALSE, message=FALSE, fig.width=8, fig.height=4}
# measures
measures1 %>%
left_join(ctry_edate, by = "Country") %>%
filter(!is.na(edate)) %>%
mutate(Date = as.numeric(Date - edate)) %>%
left_join(ctry_names, by = "Country") %>%
select(Country, Date, edate, Measure_L1) -> edates3
edates3 [edates3$Country== "Diamond Princess",] %>%
group_by(Date, Measure_L1) %>%
summarise(
count = n()
) %>%
ungroup() %>%
arrange(Measure_L1, Date) %>%
group_by(Measure_L1) %>%
mutate(count = cumsum(count)) %>%
complete(Date = min(edates3$Date):max(edates3$Date)) %>%
fill(count) %>%
replace_na(list(count = 0)) %>%
ggplot(aes(x = Date, fill = Measure_L1, y = count)) +
theme_minimal() + labs(
x = lab_x,
y = "Percentage share of all interventions at event date",
fill = ""
) +
geom_area(position = "fill") +
scale_y_continuous(labels = scales::percent)+
labs(title="Diamond Princess")+
theme(legend.title = element_blank())+
theme(legend.position = "bottom")+
theme(legend.key.size = unit(0.5, "cm"),
legend.text = element_text(size = 10)) +
guides(fill=guide_legend(nrow=4, byrow=TRUE))
```