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 last updated on <2021-07-17 Sat>.

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:

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

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
  Jul 01 Jul 02 Jul 03 Jul 04 Jul 05 Jul 06 Jul 07 Jul 08 Jul 09 Jul 10 Jul 11 Jul 12 Jul 13 Jul 14 Jul 15 Jul 16 Jul 17
Abruzzo 50 23 28 25 7 33 35 49 32 34 25 0 33 42 50 25 34
Basilicata 16 4 11 6 1 7 12 15 7 9 5 0 3 10 5 10 11
Calabria 27 13 56 24 11 26 38 54 48 16 54 13 45 56 32 77 51
Campania 107 98 139 110 68 108 208 162 226 210 169 69 136 188 234 204 238
Emilia-Romagna 61 46 65 52 58 51 62 94 99 96 93 118 76 117 167 200 207
Friuli Venezia Giulia 15 21 10 9 2 13 22 19 17 28 6 17 15 42 21 26 30
Lazio 72 64 85 83 83 58 104 112 135 176 164 172 166 208 353 443 500
Liguria 12 11 7 13 8 7 20 16 17 26 26 9 25 40 31 54 55
Lombardia 136 143 140 131 51 129 100 215 230 205 250 95 241 420 381 399 438
Marche 46 28 32 41 4 39 52 42 19 35 39 9 21 60 40 52 53
Molise 1 0 1 3 0 0 4 4 10 0 7 1 0 16 10 23 9
P.A. Bolzano 14 4 7 4 1 15 6 5 12 12 11 0 18 13 22 10 34
P.A. Trento 5 7 3 6 0 1 4 4 3 7 6 2 10 24 23 33 26
Piemonte 20 25 35 40 15 38 31 42 40 33 47 17 53 84 68 115 55
Puglia 40 43 47 25 15 60 49 58 44 41 34 19 97 44 42 46 81
Sardegna 10 25 8 21 9 21 25 28 51 43 52 51 86 135 112 140 190
Sicilia 137 115 134 102 58 144 109 219 201 192 183 150 174 288 353 386 431
Toscana 53 58 50 49 41 59 41 94 79 63 87 66 65 90 173 169 222
Umbria 3 9 5 11 3 1 7 11 13 17 6 4 15 15 20 56 30
Valle d’Aosta 2 0 3 0 0 0 1 2 1 0 2 0 1 0 0 5 2
Veneto 55 57 66 53 45 97 80 149 106 157 125 76 254 261 318 425 424

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