Some Graphs about COVID-19 in Italy

Table of Contents

Menu

Introduction

This page contains various plots generated from that data using Org Mode and R: no fancy web services, just plain-old off-line generation. On top of being an interesting exercise on R and literate programming in Emacs, I use this page to get an idea of the evolution of the pandemic in Italy.

This page was created on <2020-03-28 Sat> and last updated on <2021-01-13 Wed>.

The source code available on the COVID-19 pages is distributed under the MIT License; the content is distributed under a Creative Commons - Attribution 4.0.

Get the data

First we get the data:

curl https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni.csv > data/dpc-covid19-ita-regioni.csv
curl https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv > data/dpc-covid19-ita-andamento-nazionale.csv 
curl https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-latest.csv > data/dpc-covid19-ita-regioni-latest.csv

R Functions

This section contains the code for plotting data. The function my_plot plots different variables of an input dataframe over time, optionally filtering over region, which is the denomination of an Italian region.

The optional argument max defines the maximum value for the x-axis, while the optional Boolean arguments textlabels and filter control, respectively, whether text labels are printed on graphs and data has to be filtered by Region.

Finally, the optional arguments variables, graphtypes, and colors are vectors, defining, respectively, the variables to plot, the type of plot, and the colors used.

my_plot <- function(region, data, max=-1, textlabels=TRUE, filter=FALSE, 
                    variables  = c("totale_casi", "nuovi_positivi", "totale_positivi", "deceduti", "dimessi_guariti"),
                    graphtypes = c("l", "h", "l", "l", "l"),
                    colors     = c("red", "black", "orange", "slategrey", "forestgreen")) {
  par(cex=1.40, las=2)

  # if asked to filter, filter data according to region
  if (filter) {
    dataframe <- subset(data, denominazione_regione == region)
  }
  else {
    dataframe <- data
  }

  if (max == -1) {
    max=max(dataframe$totale_casi)
  }

  plot(x=1, 
       xlim=c(min(data$data), max(data$data)),
       ylim=c(0,max),
       type="n",
       main = region,
       xlab="",
       ylab="",
       xaxt="n")

  axis.Date(1, at=dataframe$data, by="days", format="%b %d")

  # do the plots, now
  for (i in 1:length(variables)) {
    lines(x=dataframe$data, y=dataframe[, variables[i]],
          type=graphtypes[i], 
          lwd=5,
          pch=16, 
          col=colors[i])
    if (textlabels) {
      text(x=dataframe$data, y=dataframe[, variables[i]], 
           label=dataframe[, variables[i]], 
           pos=2, 
           col=colors[i])
    }
  }

  values = sprintf("(%s)", dataframe[nrow(dataframe), variables])
  legend("topleft", legend=paste(variables, values), col=colors, lty=1, cex=1.6)
  grid(col = "lightgray")
}

Then we read the data from the CSV files of the Civil Protection repository:

PATH="./data/"

# evolution over time, by Region
data = read.csv(file.path(PATH, "dpc-covid19-ita-regioni.csv"))
data$data <- as.Date(data$data)

# evolution over time at the National level
national = read.csv(file.path(PATH, "dpc-covid19-ita-andamento-nazionale.csv"))
national$data <- as.Date(national$data)

# latest regional data
latest = read.csv(file.path(PATH, "dpc-covid19-ita-regioni-latest.csv"))
latest$data <- as.Date(national$data)

We are now ready to print and plot the data.

This Week in Italy

cols = c(
  "ricoverati_con_sintomi", 
  "terapia_intensiva",
  "totale_ospedalizzati",
  "isolamento_domiciliare", 
  "totale_positivi",
  "nuovi_positivi",
  "dimessi_guariti",
  "deceduti",
  "totale_casi"
)
labels = c(
  "In hospitals with symptoms", 
  "In ICUs",
  "Total hospitalized",
  "Quarantined at home", 
  "Active cases",
  "New cases",
  "Recovered",
  "Deaths",
  "Total number of cases"
)

Today = unlist(national[nrow(national), cols])
Yesterday = unlist(national[nrow(national) - 1, cols])
TwoDaysAgo = unlist(national[nrow(national) - 2, cols])
ThreeDaysAgo = unlist(national[nrow(national) - 3, cols])
FourDaysAgo = unlist(national[nrow(national) - 4, cols])
FiveDaysAgo = unlist(national[nrow(national) - 5, cols])

output_frame <- data.frame(labels, FiveDaysAgo, FourDaysAgo, ThreeDaysAgo, TwoDaysAgo, Yesterday, Today)
colnames(output_frame) <- rev(seq(Sys.Date(), by="-1 day", length.out=7))
colnames(output_frame)[1] <- "Label"
output_frame
Label 2021-01-08 2021-01-09 2021-01-10 2021-01-11 2021-01-12 2021-01-13
In hospitals with symptoms 23313 23260 23427 23603 23712 23525
In ICUs 2587 2593 2615 2642 2636 2579
Total hospitalized 25900 25853 26042 26245 26348 26104
Quarantined at home 544489 546989 553890 549734 543692 538670
Active cases 570389 572842 579932 575979 570040 564774
New cases 17533 19978 18627 12532 14242 15774
Recovered 1589590 1606630 1617804 1633839 1653404 1673936
Deaths 77911 78394 78755 79203 79819 80326
Total number of cases 2237890 2257866 2276491 2289021 2303263 2319036

Variations with respect to previous day

We now plot the variations in the last week, that is the difference between a day and the previous day. In many cases, the lower the number, the better. In other cases (e.g., Recovered), the higher, the better.

Diff4 = FourDaysAgo - FiveDaysAgo
Diff3 = ThreeDaysAgo - FourDaysAgo
Diff2 = TwoDaysAgo - ThreeDaysAgo 
Diff1 = Yesterday - TwoDaysAgo
Diff0 = Today - Yesterday

diff_frame <- data.frame(labels, Diff4, Diff3, Diff2, Diff1, Diff0)
diff_frame
labels Diff4 Diff3 Diff2 Diff1 Diff0
In hospitals with symptoms -53 167 176 109 -187
In ICUs 6 22 27 -6 -57
Total hospitalized -47 189 203 103 -244
Quarantined at home 2500 6901 -4156 -6042 -5022
Active cases 2453 7090 -3953 -5939 -5266
New cases 2445 -1351 -6095 1710 1532
Recovered 17040 11174 16035 19565 20532
Deaths 483 361 448 616 507
Total number of cases 19976 18625 12530 14242 15773

See also the historical series of new cases in Italy.

Situation in Italy

Overall Situation

Evolution over time.

my_plot("Italia", national, textlabels=FALSE)

italia.png

Breakdown of Quarantine

It tells where people with COVID-19 are spending their quarantine, that is, a breakdown of the “yellow” line of the previous plot.

The blue line is the number of people hospedalized during the (first) lockdown. Now the capacity of the health system should be higher, but it seems something to look at (although the situation differs from region to region).

  my_plot("Italia", 
          national,
          max(national$isolamento_domiciliare), textlabels=FALSE, filter=FALSE, 
          variables=c("ricoverati_con_sintomi", "terapia_intensiva", "totale_ospedalizzati", "isolamento_domiciliare"),  
          graphtypes=c("l", "l", "l", "l", "h"),
          colors=c("#FECEAB", "#EC2049", "#E84A5F", "#A7226E"))
abline(h = national[38,]$totale_ospedalizzati, col="#330000", lwd=2, lty=3)
abline(v = as.Date("2020-10-25"), col="#330000", lwd=2, lty=3)

hospitalized.png

Focus on Trentino, Liguria, Veneto and Lombardia

Situation in Trentino

my_plot("P.A. Trento", data, filter=TRUE, textlabels=FALSE)

trentino.png

Situation in Liguria

my_plot("Liguria", data, filter=TRUE, textlabels=FALSE)

liguria.png

Situation in Veneto

my_plot("Veneto", data, filter=TRUE, textlabels=FALSE)

veneto.png

Situation in Lombardia

my_plot("Lombardia", data, filter=TRUE, textlabels=FALSE)

lombardia.png

Situation by Region

Situation by Region

# how many rows and columns?
par(mfrow=c(11, 2))

max <- max(data$totale_casi)

regions <- c("Valle d'Aosta", "Piemonte", "Liguria", "Lombardia", "Veneto",
             "P.A. Trento", "P.A. Bolzano", "Friuli Venezia Giulia",
             "Emilia-Romagna", "Toscana", "Marche", "Umbria",
             "Lazio", "Abruzzo", "Molise", "Campania",
             "Puglia", "Basilicata", "Calabria", "Sicilia",
             "Sardegna")
for (region in regions) {
  my_plot(
    region, data, filter=TRUE, textlabels=FALSE,
          variables=c("totale_casi", "totale_positivi", "deceduti", "dimessi_guariti"),
          max = max,
          graphtypes=c("l", "l", "l", "l"),
          colors=c("red", "orange", "slategrey", "forestgreen"))
}

cases_by_region.png

Author: Adolfo Villafiorita

Last modified: 2021-01-13 Wed 18:49 (created on: 2020-03-28 Sat 00:00)

Published: 2021-01-13 Wed 18:51