Commit 76b73ff8 authored by Facundo Muñoz's avatar Facundo Muñoz ®️
Browse files

Report Europe: use deaths_by_ctry_dt computed at the plan level rather than...

Report Europe: use deaths_by_ctry_dt computed at the plan level rather than creating intermediate objects.
parent c6df1d78
......@@ -53,44 +53,48 @@ loadd(
eust,
pop_countries_2019,
covid,
lockdown_dates
lockdown_dates,
deaths_by_ctry_dt # deaths by country and date
)
```
```{r mydata, include = F}
```{r european-countries}
## European countries
european_countries <- sort(c(eu28, efta, candi, noneu)) %>%
# Exclude Liechtensteing because of small population size
.[-which(. == "Liechtenstein")] %>%
standardise_country_names()
```
```{r mydata, include = F}
## text size
cex <- .7
## string for today
sdt <- format(Sys.Date(), "%d %b %Y")
## Extract mortality data
dfr <- base::subset(
covid,
subset = name %in% european_countries,
select = c("date", "name", "deaths"))
## Add lockdown date
z <- merge(x = aggregate(deaths ~ date + name,
data = dfr, FUN = sum),
y = lockdown_dates,
all.x = T,
by = "name")
z$date <- as.Date(as.character(z$date))
## Deaths by country and date of European countries
## with population and lockdown date added
Dfr <- deaths_by_ctry_dt %>%
filter(name %in% european_countries) %>%
left_join(
lockdown_dates,
by = "name"
) %>%
left_join(
pop_countries_2019,
by = "name"
) %>%
mutate(
name = factor(name)
) %>%
select(name, date, deaths, pop, lockdown)
## add population size
Dfr <- merge(pop_countries_2019,
z,
by = "name")
## compute overall stats
......@@ -490,8 +494,7 @@ onam2 <- onam[!(onam %in% c("Turkey", nam100))]
## the condition on deaths >= 0 is needed because Spain has declared a
## negative count in early June
Dfr <- subset(merge(pop_countries_2019, z, by = "name"),
name %in% onam2 & deaths >= 0)
Dfr <- subset(Dfr, name %in% onam2 & deaths >= 0)
## number of rows (countries) / page
nbr <- 7
......@@ -606,23 +609,11 @@ plot(dmrplot(dmr = Dfr,
```{r growthRate}
z1 <- subset(covid,
select = c("date", "name", "deaths"))
## aggregate deaths by country and date
z2 <- aggregate(deaths ~ date + name, data = z, FUN = sum)
z2$date <- as.Date(as.character(z2$date))
## merge covid data with pop size, and lockdonw date
z3 <- merge(merge(pop_countries_2019, z2, by = "name"),
lockdown_dates,
by = "name")
## define a new variable "day" with day=0 at the frist death
z4 <- do.call(
"rbind",
by(z3,
list(name = z3$name),
by(Dfr,
list(name = Dfr$name),
function(x){
x$day = as.numeric(x$date - min(x$date))
x
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment