New Cases in Italy

Table of Contents



This page focuses on new cases in Italy.

This page was created on <2020-08-01 Sat> and last updated on <2021-06-13 Sun>.

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.

R Functions

We read the data from the CSV files of the Civil Protection repository:


# 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
new_national = read.csv(file.path(PATH, "dpc-covid19-ita-andamento-nazionale.csv"))
new_national$data <- as.Date(new_national$data)

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

We then output a table of new cases from R, which we then use in Ruby. (The table is not exported to HTML.)

Inferior Ruby shells perform very badly with long input lines. Make sure you don’t pass the variable to a Ruby :session or the evaluation will break, while IRB tries to cope with the declaration of the input variable.

If you need a :session, you should read data directly from the Ruby session, rather than passing it as a variables.

new_national[, c("data", "nuovi_positivi")]

New Cases in Italy

Line Plot

The shaded area corresponds to the lockdown. The red horizontal line allows to compare the latest data with historical data.

p = plot(new_national$nuovi_positivi ~ new_national$data, type="l", lwd=6, pch=16, cex=1.6, col=c("#3B3176"))
#text(new_national$nuovi_positivi ~ new_national$data, labels=new_national$nuovi_positivi, pos=2, cex=1.3)
#abline(v = as.Date("2020-10-25"), col="#FF0000", lwd=3)

grid(p, col = "black", lty="dotted")
#rect(as.Date("2020-03-09"), -200, as.Date("2020-05-19"), 7000, border = "#AA0055", col = "#AA0055", density=2)

text(x = as.Date("2020-03-25"), y = 8000, "First Wave", col="#FF0000")
abline(h = new_national[27,]$nuovi_positivi, col="#FF0000", lwd=2)
#abline(v = as.Date("2020-03-01"), col="#FF0000", lwd=2)

abline(h = 41000, col="#FF0000", lwd=2)
abline(v = as.Date("2021-03-01"), col="#FF0000", lwd=2)

text(x = as.Date("2020-11-15"), y = 42000, "Second Wave", col="#FF0000")


Calendar Heatmap

<div id="heatmap-total"></div>
    data: [
    #{ { |x| "{ day: \"%s\", count: %d }" % [x[0], x[1].to_i] }.join(",") }
    date_var: "day",
    fill_var: "count",
    target: "#heatmap-total"

New Cases by Region

Tabular Data

The table is built as follows:

  • egrep selects entries in the current month, getting the current month from the date command
  • the first sed gets rid of the “T17:00:00” timestamp in dates
  • the second sed compacts the date, by removing the year and replacing the month number with its name
  • datamash pivots the table by region and date
current_month=$(date +"%b")
current_month_no=$(date +"%m")
year=$(date +"%Y")

egrep ${year}-${current_month_no} ./data/dpc-covid19-ita-regioni.csv | sed -e "s/T1[78]:00:00//g" | sed -e "s/${year}-${current_month_no}-/${current_month} /g" | datamash -t, crosstab 4,1 sum 13

Line Plots

# 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",
for (region in regions) {