-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
167 lines (137 loc) · 5.63 KB
/
README.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
---
output: github_document
---
# Monkeypox ![GitHub last commit](https://img.shields.io/github/last-commit/dslabscl/covid-data)
This report is automatically compiled using data from [Global.health](https://global.health).
The original data is retrieved from [this repository](https://github.com/globaldothealth/monkeypox).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, dev = "svg")
```
```{r}
library(data.table)
library(ggplot2)
dat <- fread("https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.csv")
meta <- fread("https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.csv")
```
## Cases per country
```{r number-countries-affected}
dat_country_count <- dat[, .(Country, Date_entry)] |> unique()
dates <- dat[, range(Date_entry, na.rm = TRUE)]
dates <- seq(from = dates[1], to = dates[2], by = 1)
countries <- dat[, unique(Country)]
dat_country_m <- matrix(
0L, nrow = length(dates), ncol = length(countries),
dimnames = list(as.character(dates), countries)
)
dat_country_m[dat_country_count[, cbind(as.character(Date_entry), Country)]] <- 1L
dat_country_m <- apply(dat_country_m, 2, cumsum, simplify = TRUE)
dat_country_m[dat_country_m > 0] <- 1
dat_country_m <- rowSums(dat_country_m)
data.table(
Date = data.table::as.IDate(names(dat_country_m)),
Count = dat_country_m
) |> ggplot(aes(x = Date, y = Count)) +
geom_line() +
labs(
y = "Count",
title = "Number of Countries reporting Monkeypox",
subtitle = paste0("Last update ", max(dat$Date_last_modified, na.rm = TRUE)),
caption = sprintf("Created by github.com/UofUEpi.\nData retrieved from github.com/globaldothealth/monkeypox.")
)
```
```{r per-country, fig.height=10}
dat_per_country <- dat[, .(n = .N), by = .(Country)]
setorder(dat_per_country, n)
dat_per_country[, Country := factor(Country, levels = Country)]
ggplot(dat_per_country, aes(x = Country, y = n + .1)) +
geom_col() +
coord_flip() +
theme(axis.text.x = element_text(angle = 45)) +
labs(
y = "Count (log-scale)",
title = "Monkeypox Confirmed Cases",
subtitle = paste0("Last update ", max(dat$Date_last_modified, na.rm = TRUE)),
caption = sprintf("Created by github.com/UofUEpi.\nData retrieved from github.com/globaldothealth/monkeypox.")
) +
scale_y_log10()
```
## Cases total
```{r timeline}
dat_per_date <- dat[, .(n = .N), by = .(Status, Date_entry)]
dat_per_date <- dat_per_date[which(complete.cases(dat_per_date))]
# Completes dates
drange <- dat_per_date[, range(Date_entry, na.rm = TRUE)]
merger <- data.table(Date_entry = seq(drange[1], drange[2], by = 1))
merger <- rbindlist(
lapply(unique(dat_per_date$Status), \(x) {
cbind(merger, data.table(Status = x))
})
)
dat_per_date <- merge(
dat_per_date,
merger, all = TRUE
)
dat_per_date[, Cumulative := cumsum(fcoalesce(n, 0L)), by = .(Status)]
# dat_per_date[, Cumulative := nafill(Cumulative, type = "nocb")]
ggplot(dat_per_date, aes(x = Date_entry, y = Cumulative)) +
geom_line(aes(colour = Status)) +
labs(
y = "Count",
title = "Monkeypox Cumulative Cases by Status",
subtitle = paste0("Last update ", max(dat$Date_last_modified, na.rm = TRUE)),
caption = sprintf("Created by github.com/UofUEpi.\nData retrieved from github.com/globaldothealth/monkeypox."),
x = "Date"
)
```
```{r newcases-smoothed, message=FALSE}
ggplot(dat_per_date[Status == "confirmed"], aes(x = Date_entry, y = fcoalesce(n, 0L))) +
geom_jitter(alpha = .5) +
geom_smooth() +
labs(
y = "Count",
title = "Daily number of confirmed cases (worldwide)",
subtitle = paste0("Last update ", max(dat$Date_last_modified, na.rm = TRUE)),
caption = sprintf("Created by github.com/UofUEpi.\nData retrieved from github.com/globaldothealth/monkeypox."),
x = "Date"
)
```
```{r newcases-per-country-smoothed, message=FALSE, fig.height=7, fig.width=10}
dat_per_country_avg <- dat[Status == "confirmed", .(Country, Date_entry)]
dat_per_country_avg <- dat[, .(n = .N), by = .(Country, Date_entry)]
drange <- dat_per_date[, range(Date_entry, na.rm = TRUE)]
merger <- data.table(Date_entry = seq(drange[1], drange[2], by = 1))
dat_per_country_avg <- merge(
dat_per_country_avg,
merger, all = TRUE
)[, n := fcoalesce(n, 0L)]
# Top 10 countries
top10 <- setorder(dat_per_country, -n) |> head(10)
top10 <- top10$Country
dat_per_country_avg[, Country := fifelse(Country %in% top10, Country, "* Rest of the world")]
setorder(dat_per_country_avg, Country, Date_entry)
dat_per_country_avg[, Cumulative := cumsum(n), by = .(Country)]
# Fancy labels and order
fancy_labels <- rbind(
dat_per_country[1:10, .(Country, Total = n)],
dat_per_country[-c(1:10), .(Country = "* Rest of the world", Total = sum(n))]
)
fancy_labels[, lab := sprintf("%s (%i)", Country, Total)]
fancy_labels[, lab := factor(lab, levels = lab, ordered = TRUE)]
dat_per_country_avg <- merge(dat_per_country_avg, fancy_labels)
dat_per_country_avg[, alevel := Total/diff(range(Total))]
dat_per_country_avg |>
ggplot(aes(x = Date_entry, y = fcoalesce(n, 0L))) +
geom_jitter(aes(colour = lab, size = Cumulative, alpha = Total)) +
geom_smooth(colour = "black", alpha = .5, lty = 2) +
scale_color_discrete()+
labs(
y = "Daily cases",
title = "Daily confirmed cases per country",
subtitle = paste0("Last update ", max(dat$Date_last_modified, na.rm = TRUE)),
caption = sprintf("Created by github.com/UofUEpi.\nData retrieved from github.com/globaldothealth/monkeypox."),
x = "Date",
colour = "Country (total cases)",
size = "Cumulative\nper country"
) +
guides(alpha = "none")
```