New Cases in Italy

Table of Contents

Menu

Introduction

This page focuses on new cases in Italy. This page was created on <2020-08-01 Sat> and regularly updated since then.

R Functions

First we read the data from the CSV files of the Civil Protection repository1:

We get it into R:

# 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)
text(x = as.Date("2020-11-15"), y = 42000, "Second Wave", col="#FF0000")

text(x = as.Date("2021-03-16"), y = 28000, "Third Wave", col="#FF0000")
abline(h = 27354, col="#FF0000", lwd=2)

p12_newcases.png

Calendar Heatmap

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

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
  Apr 01 Apr 02 Apr 03 Apr 04 Apr 05 Apr 06 Apr 07 Apr 08 Apr 09 Apr 10 Apr 11
Abruzzo 2301 2068 1800 762 2900 1982 2101 2079 2122 1649 744
Basilicata 1061 935 625 505 1094 712 822 731 701 538 350
Calabria 3477 2502 1692 1997 3641 2342 2326 2173 2100 1619 1431
Campania 7903 7537 6373 3384 10099 7277 7435 7224 6795 4302 2862
Emilia-Romagna 4941 4600 4363 3195 3103 5343 4942 5136 4717 4565 2909
Friuli Venezia Giulia 1417 1169 712 282 1562 1133 1223 1141 1206 808 210
Lazio 8460 9115 6533 3834 9903 7782 7591 6849 7255 6415 3780
Liguria 1507 1576 1011 523 1979 1518 1537 1481 1490 1194 569
Lombardia 9053 8782 6371 2512 11666 9094 9368 8681 8540 6611 2560
Marche 2386 2180 1885 860 2814 1981 2249 2086 1885 1789 714
Molise 318 515 389 166 378 430 464 370 180 422 181
P.A. Bolzano 573 493 357 242 847 512 514 552 443 259 145
P.A. Trento 383 401 297 163 536 466 489 473 439 353 145
Piemonte 3109 2665 1724 2566 3895 3368 3330 3252 3020 1758 2832
Puglia 6872 6670 4929 2683 8441 5773 5578 5352 5478 4137 1859
Sardegna 2008 1677 1064 760 2631 1989 1780 1848 1462 1207 1164
Sicilia 4749 4952 3435 1993 5769 4566 4142 4448 4005 3548 1818
Toscana 4793 4698 3882 1640 5974 4458 4751 4395 4134 3653 1606
Umbria 1639 1383 1203 500 1745 1473 1270 1267 1138 1130 621
Valle d’Aosta 67 64 62 15 116 90 79 69 62 78 21
Veneto 7333 6821 4881 2048 9080 6989 7605 6928 6820 5341 1847

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",
             "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

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.

Footnotes:

1

The CSV files containing the data are updated by the first code block in index.html.