Commit f7edc186 authored by Renaud Lancelot's avatar Renaud Lancelot 🌍
Browse files

Resolved conflicts with Facundo's updates.

parents e9550fc9 7c10514c
Pipeline #14110 failed with stage
in 3 minutes and 14 seconds
......@@ -6,9 +6,18 @@ FROM rocker/geospatial
LABEL maintainer="Facundo Muñoz facundo.munoz@cirad.fr"
# # Install external dependencies
# RUN export DEBIAN_FRONTEND=noninteractive; apt-get -qq update \
# && apt-get install -y --no-install-recommends \
# Install external dependencies
## Install MS Fonts (using Arial for the pdf document)
## Pre-accept licence
## https://github.com/captnswing/msttcorefonts
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install -y --no-install-recommends fontconfig ttf-mscorefonts-installer
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -qq update \
&& apt-get install -y --no-install-recommends \
fontconfig \
ttf-mscorefonts-installer \
# libv8-dev \
# libjq-dev \
# libprotobuf-dev \
......@@ -23,11 +32,13 @@ LABEL maintainer="Facundo Muñoz facundo.munoz@cirad.fr"
# libudunits2-dev \
# libcairo2-dev \
# qpdf \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/
# Install required LaTeX packages for pdf reports
RUN tlmgr install \
RUN tlmgr update --self \
&& tlmgr install \
amsfonts \
amsmath \
latex-amsmath-dev \
......@@ -61,7 +72,13 @@ geometry \
latex-tools-dev \
booktabs \
grffile \
epstopdf-pkg
epstopdf-pkg \
euenc \
fontspec \
lm-math \
tipa \
unicode-math \
xunicode
# Install R-package dependencies for compiling reports
RUN ["install2.r", "ade4", "Cairo", "countrycode", "cshapes", "drake", "furrr", "future.callr", "ggthemes", "ggrepel", "here", "hrbrthemes", "janitor", "knitr", "latticeExtra", "pacman", "readxl", "rjson", "rmarkdown", "rmdformats"]
......
......@@ -54,17 +54,20 @@ loadd(
eust,
pop_countries_2019,
covid,
lockdown_dates
lockdown_dates,
deaths_by_ctry_dt, # deaths by country and date
data_update_date, # date of update of covid data
)
```
```{r mydata, include = F}
```{r european-countries}
## European countries
zctr <- sort(c(eu28, efta, candi, noneu))
european_countries <- zctr[-which(zctr == "Liechtenstein")]
european_countries <- sort(c(eu28, efta, candi, noneu)) %>%
# Exclude Liechtensteing because of small population size
.[-which(. == "Liechtenstein")] %>%
standardise_country_names()
## text size
cex <- .7
......@@ -72,66 +75,86 @@ cex <- .7
## clean the data
covid$name <- standardise_country_names(covid$name)
## Lockdown date in European countries
conf <- base::subset(lockdown_dates,
subset = name %in% european_countries)
## 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 = conf,
all.x = T,
by = "name")
z$date <- as.Date(as.character(z$date))
## add population size
Dfr <- merge(pop_countries_2019,
z,
by = "name")
## compute overall stats
## cumulative death rate sorted from the highest to the lowest
cdr <- 100 * tapply(Dfr$deaths, factor(Dfr$name), sum) /
tapply(Dfr$pop, factor(Dfr$name), unique)
```
## order name levels according to decreasing cumulative death rate
Dfr$name <- factor(as.character(Dfr$name))
o <- order(cdr, decreasing = T)
```{r country-data}
## Variables relative to European countries:
## group, name, lockdown date, population, cumulated deaths,
## and death rate.
country_data <-
map_dfr(
list("eu28", "efta", "candi", "noneu"),
~tibble(
group = .,
name = get(.)
)
) %>%
filter(name != "Liechtenstein") %>%
left_join(
lockdown_dates,
by = "name"
) %>%
left_join(
pop_countries_2019,
by = "name"
) %>%
mutate_if(is.character, as.factor) %>%
left_join(
deaths_by_ctry_dt %>%
group_by(name) %>%
summarise(
cum_deaths = sum(deaths),
.groups = "drop"
),
by = "name"
) %>%
mutate(
## Cumulated number of deaths per 100 K hab.
## Note that pop is expressed in thousands.
death_rate = cum_deaths / pop * 100
) %>%
## Arrange rows by descending order of death rate
arrange(desc(death_rate))
## country names ordered by decreasing cumulative death rate
onam <- names(cdr)[o]
ocdr <- cdr[o]
```
## number of deaths by country
nd <- tapply(Dfr$deaths, Dfr$name, sum, na.rm = T)
ond <- nd[o]
```{r mydata, include = F}
agg <- aggregate(deaths ~ name, data = Dfr, FUN = sum)
nam100 <- as.character(agg$name[agg$deaths < 100])
## Deaths by country and date of European countries
## with population and lockdown date added
Dfr <- deaths_by_ctry_dt %>%
inner_join(
country_data,
by = "name"
) %>%
mutate(
# Order name levels in decreasing order of death rate
name = fct_reorder(name, death_rate, .desc = TRUE)
) %>%
select(name, date, deaths, pop, lockdown)
## Names of countries with less than 100 cumulated deaths
nam100 <- country_data %>%
filter(cum_deaths < 100) %>%
pull(name)
## character string with the number of deaths by country
sond <- format(ond, big.mark = ",", trim = T)
sond <- format(country_data$cum_deaths, big.mark = ",", trim = T)
## character string with the cumulative death rate by country
socdr <- sprintf(ocdr, fmt = "%##.1f", digits = 0)
socdr <- sprintf(country_data$death_rate, fmt = "%##.1f", digits = 0)
## overall number of deaths
ttnd <- sum(nd)
ttnd <- sum(country_data$cum_deaths)
## character string for overall number of deaths
sttnd <- format(ttnd, big.mark = ",")
## overall population size
cond <- pop_countries_2019$name %in% european_countries
ttpop <- 1000 * sum(pop_countries_2019$pop[cond])
## overall population size (in thousands)
ttpop <- sum(country_data$pop)
## character string for overall pop size
sttpop <- format(ttpop / 1e6, digits = 4, nsmall = 1, big.mark = ",")
......@@ -167,7 +190,7 @@ sttcdr <- format(ttcdr, digits = 3)
## Main results {-}
As per `r sdt`, in the `r length(european_countries)` countries
As per `r data_update_date`, in the `r length(european_countries)` countries
accounted for, the total number of deaths is now `r sttnd` for an
overall population size of `r sttpop` millions, representing a
cumulative death rate of `r sttcdr` deaths $10^{-5}$ inhabitants.
......@@ -299,22 +322,19 @@ Liechtenstein was excluded from the study because of its small population size.
## Cumulative death rate
In the `r length(european_countries)` countries accounted for$^1$,
In the `r length(european_countries)` countries accounted for^[List of countries (number of deaths in braces): `r collapse(nam = levels(Dfr$name), cnt = sond)`.],
the total number of deaths is now `r sttnd` for an overall population size of
`r sttpop` millions, representing a cumulative death rate of
`r sttcdr` deaths $10^{-5}$ inhabitants (inh.).
$^1$ List of countries (number of deaths in braces): `r collapse(nam = onam, cnt = sond)`.
### By country{-}
```{r cumul, include = T, fig.height=10, fig.cap = cap}
cap <- paste("Cumulative COVID-19 related death rate from the start",
"of the epidemic to", sdt, "in Europe. South-western",
"of the epidemic to", data_update_date, "in Europe. South-western",
"European countries are labelled in red.",
"Total deaths are indicated within braces at the",
"right of each data point.")
......@@ -325,13 +345,14 @@ red <- c("Belgium", "France", "Ireland", "Italy", "Luxembourg",
lbl <- paste0("(", sond, ")")
cex <- 0.85
dotplot( ~ rev(ocdr),
xlim = extendrange(range(ocdr), f = c(.05, .2)),
scales = list(cex = cex, tck = .5,
y = list(labels = rev(onam),
col = ifelse(rev(onam) %in% red, 2, 1))),
dotplot( ~ rev(setNames(death_rate, name)),
data = country_data,
xlim = extendrange(range(country_data$death_rate), f = c(.05, .2)),
scales = list(cex = cex, tck = .5,
y = list(labels = rev(country_data$name),
col = ifelse(rev(country_data$name) %in% red, 2, 1))),
cex = cex,
col = ifelse(rev(onam) %in% red, 2, 1),
col = ifelse(rev(country_data$name) %in% red, 2, 1),
aspect = 1.5,
xlab = list("Deaths / 100,000 inh.",
cex = cex)) +
......@@ -344,9 +365,10 @@ dotplot( ~ rev(ocdr),
gp = gpar(cex = cex,
col = ifelse(rev(onam) %in% red, 2, 1))
),
data = list(lbl = lbl, cex = cex, red = red, onam = onam)
data = list(lbl = lbl, cex = cex, red = red, onam = country_data$name)
)
```
### Spatial distribution{-}
......@@ -370,9 +392,9 @@ roi2 <- spTransform(roi, merc)
## cumulative mortality
covmap2$cumdr <- NA
for(i in seq_along(onam)){
xname <- onam[i]
xcumdr <- ocdr[i]
for(i in seq.int(nlevels(Dfr$name))){
xname <- levels(Dfr$name)[i]
xcumdr <- country_data$death_rate[i]
covmap2@data$cumdr[which(covmap2@data$CNTRY_NAME == xname)] <- xcumdr
}
......@@ -383,32 +405,32 @@ for(i in seq_along(onam)){
cap <- paste0(
"Cumulative mortality rate (deaths / 100,000 inh.) ",
"attributed to COVID-19 in Europe: situation on ", sdt,
"attributed to COVID-19 in Europe: situation on ", data_update_date,
". The countries are listed in the legend and numbered on ",
"the map (number of deaths in braces).")
num <- sprintf(seq(length(onam)), fmt = "%02d")
num <- sprintf(seq.int(nlevels(Dfr$name)), fmt = "%02d")
## colors for the map
cols <- colorRampPalette(rev(brewer.pal(n=9, "RdYlGn"))[-(1:2)])
labs <- paste0(num, " ", onam, " (", sond, ")")
labs <- paste0(num, " ", levels(Dfr$name), " (", sond, ")")
nch <- nchar(labs)
slabs <- labs[which(nch == max(nch))]
ocovmap2 <- covmap2[covmap2$CNTRY_NAME %in% onam, ]
ocovmap2 <- covmap2[covmap2$CNTRY_NAME %in% levels(Dfr$name), ]
oXY <- data.frame(coordinates(ocovmap2))
names(oXY) <- c("x", "y")
oXY$name <- as.character(ocovmap2$CNTRY_NAME)
num <- unlist(sapply(oXY$name, function(x) which(onam == x)))
num <- unlist(sapply(oXY$name, function(x) which(levels(Dfr$name) == x)))
## parameters of the map
cex <- .75
e <- raster::extent(ocovmap2)
H <- stringHeight(slabs)
L <- stringWidth(slabs)
n <- length(onam)
n <- nlevels(Dfr$name)
kex <- 1.1
spplot(ocovmap2, zcol = "cumdr",
......@@ -444,14 +466,15 @@ spplot(ocovmap2, zcol = "cumdr",
* **The most affected countries are located in south-western
Europe$^1$, at the exception of Sweden** (ranking
`r which(onam == "Sweden")` on fig. \@ref(fig:covmap)), where
Europe^[Belgium, France, Ireland, Italy, Luxembourg, Portugal, Spain, The
Netherlands, The United Kingdom.], at the exception of Sweden** (ranking
`r which(levels(Dfr$name) == "Sweden")` on fig. \@ref(fig:covmap)), where
strict lockdown measures were not adopted. Indeed, the cumulative
death rate (fig. \@ref(fig:cumul)) is contrasted between these
south-Western European countries and the others. For instance, low
death rates were reported in Germany
(`r socdr[which(onam == "Germany")]` $10^{-5}$ inh.), or even lower
in Poland (`r socdr[which(onam == "Poland")]` $10^{-5}$ inh.).
(`r socdr[which(levels(Dfr$name) == "Germany")]` $10^{-5}$ inh.), or even lower
in Poland (`r socdr[which(levels(Dfr$name) == "Poland")]` $10^{-5}$ inh.).
* Low death rates are reported in Finland, the Baltic countries,
Central Europe, and south-eastern Europe. These countries are
......@@ -473,8 +496,6 @@ spplot(ocovmap2, zcol = "cumdr",
be the case that late mortality cases were not reported by this country.
$^1$ Belgium, France, Ireland, Italy, Luxembourg, Portugal, Spain, The
Netherlands, The United Kingdom.
\newpage
......@@ -496,12 +517,11 @@ cap <- paste("Daily death rate (count / 100,000 inh. / d)",
## add population size
## we discard countries with < 100 deaths
onam2 <- onam[!(onam %in% c("Turkey", nam100))]
onam2 <- levels(Dfr$name)[!(levels(Dfr$name) %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
......@@ -614,6 +634,7 @@ dmrplot(dmr = Dfr,
```{r growthRate}
<<<<<<< HEAD
z1 <- subset(covid,
select = c("date", "name", "deaths"))
......@@ -626,11 +647,13 @@ z3 <- merge(merge(pop_countries_2019, z2, by = "name"),
conf,
by = "name")
=======
>>>>>>> 7c10514c2ef3615d8f3eacbf3d37f6850cc13b07
## 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
......
......@@ -13,7 +13,7 @@ plan <- drake_plan(
## ),
## clean_data = raw_data %>% cleanup(),
#### SOURCE DATA ####
# SOURCE DATA -------------------------------------------------------------
## Total population counts and densities by Country, Year and Sex.
## Source: United Nations'[World Population Prospects
......@@ -35,12 +35,16 @@ plan <- drake_plan(
covid = ecdc_covid19(last_day),
## String notice for data update
data_update_date = format(last_day, "%d %b %Y"),
## Lock-down dates
lockdown_dates = read_excel(file_in("data/lockdown.xlsx")) %>%
transmute(
name = standardise_country_names(raster::trim(name)),
lockdown = as.Date(lockdown)
),
## GIS vector layer for European countries (EU 27 + UK + EFTA +
## candidate countries + non-EU countries). Source GADM.org
## version 3.6
......@@ -51,6 +55,13 @@ plan <- drake_plan(
## countries described above
roi_europe_light = readOGR(dsn = "data/roi_europe_light.gpkg",
layer = "roi_europe_light"),
geo_europe = readOGR(dsn = file_in("data/geo_europe.gpkg"),
layer = "geo_europe"),
## GIS vector layer for the region of interest covering European
## countries described above
roi_europe = readOGR(dsn = file_in("data/roi_europe.gpkg"),
layer = "roi_europe"),
## Europe and neighbour countries
## EUrope 27 + UK
......@@ -73,8 +84,17 @@ plan <- drake_plan(
"Georgia", "Israel", "Jordan", "Lebanon", "Libya",
"Moldova", "Morocco", "Syria", "Tunisia", "Ukraine"),
#### DERIVED DATA ####
# DERIVED DATA ------------------------------------------------------------
## Deaths by country and date
deaths_by_ctry_dt =
covid %>%
group_by(date, name) %>%
summarise(deaths = sum(deaths)) %>%
ungroup() %>%
mutate(date = as.Date(date)),
## Population counts in thousands of people
pop_countries_2019 = pop_countries(world_population, year = 2019),
## today (ANSI)
......@@ -140,7 +160,7 @@ plan <- drake_plan(
## quiet = FALSE
## ),
#### Website and README ####
# WEBSITE AND README ------------------------------------------------------
readme_md =
rmarkdown::render(
knitr_in("README.Rmd"),
......
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