Some Graphs about COVID-19 in Italy

Menu

Table of Contents

The Italian Civil Protection has a repository on GitHub with data about COVID-19 in Italy. This page contains various plots generated from the data using Org Mode and R. No fancy web services, just plain-old off-line generation. In the bookmarks page you can find data updated more frequently (and reliably).

This page was last updated on: <2020-03-28 Sat>.

See also new cases for a specific focus on new cases in Italy.

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("o", "h", "o", "o", "o"),
                    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=3,
          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="/home/adolfo/Downloads/COVID-19/"

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

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

# latest regional data
latest = read.csv(file.path(PATH, "dati-regioni/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 2020-08-03 2020-08-04 2020-08-05 2020-08-06 2020-08-07 2020-08-08
In hospitals with symptoms 708 734 761 764 762 779
In ICUs 42 41 41 41 42 42
Total hospitalized 750 775 802 805 804 821
Quarantined at home 11706 11699 11680 11841 11890 12103
Active cases 12456 12474 12482 12646 12694 12924
New cases 239 159 190 384 402 552
Recovered 200460 200589 200766 200976 201323 201642
Deaths 35154 35166 35171 35181 35187 35190
Total number of cases 248070 248229 248419 248803 249204 249756
my_plot("Italia", 
        national,
        max(national$isolamento_domiciliare), textlabels=FALSE, filter=FALSE, 
        variables=c("ricoverati_con_sintomi", "terapia_intensiva", "totale_ospedalizzati", "isolamento_domiciliare", "nuovi_positivi"),  
        graphtypes=c("o", "o", "o", "o", "h"),
        colors=c("#FECEAB", "#EC2049", "#E84A5F", "#A7226E", "#363636"))

hospitalized.png

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 26 27 3 -2 17
In ICUs -1 0 0 1 0
Total hospitalized 25 27 3 -1 17
Quarantined at home -7 -19 161 49 213
Active cases 18 8 164 48 230
New cases -80 31 194 18 150
Recovered 129 177 210 347 319
Deaths 12 5 10 6 3
Total number of cases 159 190 384 401 552

See also the historical series of new cases in Italy.

Number of Tests and Number of People Tested

test_cols = c(
  "tamponi", 
  "casi_testati"
)
test_labels = c(
  "Tests", 
  "People tested"
)

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

output_frame <- data.frame(test_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 2020-08-03 2020-08-04 2020-08-05 2020-08-06 2020-08-07 2020-08-08
Tests 6916765 6940801 6984589 7041040 7099713 7158909
People tested 4118068 4131535 4155026 4184765 4216934 4247326
Diff4 = FourDaysAgo - FiveDaysAgo
Diff3 = ThreeDaysAgo - FourDaysAgo
Diff2 = TwoDaysAgo - ThreeDaysAgo 
Diff1 = Yesterday - TwoDaysAgo
Diff0 = Today - Yesterday

diff_frame <- data.frame(test_labels, Diff4, Diff3, Diff2, Diff1, Diff0)
diff_frame
testlabels Diff4 Diff3 Diff2 Diff1 Diff0
Tests 24036 43788 56451 58673 59196
People tested 13467 23491 29739 32169 30392

Plots

Situation in Italy

Evolution over time.

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

italia.png

Situation in Trentino

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

trentino.png

dataframe <- subset(data, denominazione_regione == "P.A. Trento")

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

output_frame <- data.frame(test_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 2020-08-03 2020-08-04 2020-08-05 2020-08-06 2020-08-07 2020-08-08
Tests 155400 155785 156181 157412 158888 160139
People tested 73042 73149 73352 73665 74061 74347
Diff4 = FourDaysAgo - FiveDaysAgo
Diff3 = ThreeDaysAgo - FourDaysAgo
Diff2 = TwoDaysAgo - ThreeDaysAgo 
Diff1 = Yesterday - TwoDaysAgo
Diff0 = Today - Yesterday

diff_frame <- data.frame(test_labels, Diff4, Diff3, Diff2, Diff1, Diff0)
diff_frame
testlabels Diff4 Diff3 Diff2 Diff1 Diff0
Tests 385 396 1231 1476 1251
People tested 107 203 313 396 286
my_plot("P.A. Trento",
        data, 
        max=200,
        filter=TRUE, 
        textlabels=FALSE,
        variables=c("nuovi_positivi"),
        graphtypes=c("h"),
        colors=c("black"))

trentino-new-cases.png

Cases in Liguria

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

liguria.png

Cases in Veneto

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

veneto.png

Cases in Lombardia

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

lombardia.png

New Cases by Region

# how many rows and columns?
par(mfrow=c(11, 2))
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, 
          max=max(data$nuovi_positivi),
          filter=TRUE, 
          textlabels=FALSE,
          variables=c("nuovi_positivi"),
          graphtypes=c("l"),
          colors=c("black"))
}

new_cases_by_region.png

Cases 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: 2020-08-05 Wed 18:20 (created on: 2020-03-28 Sat 00:00)

Published: 2020-08-08 Sat 11:32