Skip to content

Instantly share code, notes, and snippets.

@christophsax
Last active April 27, 2020 20:27
Show Gist options
  • Save christophsax/5f675b28fe0464ccc857b4e7b8355bb1 to your computer and use it in GitHub Desktop.
Save christophsax/5f675b28fe0464ccc857b4e7b8355bb1 to your computer and use it in GitHub Desktop.
Covid-19 Italy and Italian Provinces
library(tidyverse)

# download all province data from
# https://github.com/pcm-dpc/COVID-19/tree/master/dati-province
url <- "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-province/dpc-covid19-ita-province.csv"
dta <- read_csv(url, col_types = cols()) %>%
  transmute(time = data, region = denominazione_regione, province = denominazione_provincia, value = totale_casi)

dta <-
  dta %>%
  # calculate new confirmed cases
  arrange(time) %>%
  group_by(province) %>%
  mutate(diff = value - lag(value)) %>%
  ungroup() %>%
  filter(!is.na(diff)) %>%
  arrange(province, time)

dta %>%
  filter(province %in% c("Lodi", "Bergamo")) %>%
  ggplot(aes(x = time, y = diff)) +
  geom_col() +
  facet_wrap(vars(province), scales = "free_y") +
  scale_y_continuous(trans='log10') +
  ggtitle("New cases in Bergamo and Lodi", "Coronavirus disease (COVID-19), log scale")+
  theme_minimal()

url <- "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-andamento-nazionale/dpc-covid19-ita-andamento-nazionale.csv"
dta <- read_csv(url, col_types = cols()) %>%
  transmute(time = data, diff = nuovi_positivi, value = totale_positivi)

dta %>%
  ggplot(aes(x = time, y = diff)) +
  geom_col() +
  scale_y_continuous(trans='log10') +
  ggtitle("New cases in Italy", "Coronavirus disease (COVID-19), log scale")+
  theme_minimal()

Created on 2020-04-27 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment