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 webservices, 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>.

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, graphtypes, colors) {
  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")

  # default values for variables to plot
  if (missing(variables)) {
     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")
  }

  # 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",
  "variazione_totale_positivi",
  "nuovi_positivi",
  "dimessi_guariti",
  "deceduti",
  "totale_casi"
)
labels = c(
  "In hospitals with symptons", 
  "In ICUs",
  "Total hospitalized",
  "Quarantined at home", 
  "Active cases",
  "Variation of 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-05-28 2020-05-29 2020-05-30 2020-05-31 2020-06-01 2020-06-02
In hospitals with symptons 8613 8185 7917 7729 7379 7094
In ICUs 553 541 521 505 489 475
Total hospitalized 9166 8726 8438 8234 7868 7569
Quarantined at home 47428 46574 44504 42732 40118 38606
Active cases 56594 55300 52942 50966 47986 46175
Variation of cases -1158 -1294 -2358 -1976 -2980 -1811
New cases 531 300 397 584 593 516
Recovered 140479 141981 144658 147101 150604 152844
Deaths 32785 32877 32955 33072 33142 33229
Total number of cases 229858 230158 230555 231139 231732 232248

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 symptons -428 -268 -188 -350 -285
In ICUs -12 -20 -16 -16 -14
Total hospitalized -440 -288 -204 -366 -299
Quarantined at home -854 -2070 -1772 -2614 -1512
Active cases -1294 -2358 -1976 -2980 -1811
Variation of cases -136 -1064 382 -1004 1169
New cases -231 97 187 9 -77
Recovered 1502 2677 2443 3503 2240
Deaths 92 78 117 70 87
Total number of cases 300 397 584 593 516

Plots

Cases in Trentino

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

trentino.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

Situation in Italy

Total number of active cases by region (This seems to have an issue with xlim)

R :session true :results graphics file output silent :file total_by_region.png :width 1500 :height 800
par(las=2)
plot(latest$totale_positivi ~ latest$denominazione_regione, xlab="Regione", ylab="Totale Attualmente Positivi")
text(x = latest$denominazione_regione, y = latest$totale_positivi, label=latest$totale_positivi, pos=3)

Evolution over time.

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

italia.png

Cases by Region

par(mfrow=c(7,3))

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

New Cases by Region

par(mfrow=c(7,3))
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

Author: Adolfo Villafiorita

Last modified: 2020-06-02 Tue 10:57 (created on: 2020-03-28 Sat 00:00)

Published: 2020-06-02 Tue 11:55