library(covid19italy) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The covid19italy R package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) pandemic outbreak in Italy. The package includes the following three datasets:
italy_total
- daily summary of the outbreak on the national levelitaly_region
- daily summary of the outbreak on the region levelitaly_province
- daily summary of the outbreak on the province level More information about the package datasets available here, and supporting dashboard available here.
Data source: Italy Department of Civil Protection
You can install the released version of covid19italy from CRAN with:
install.packages("covid19italy")
Or, install the most recent version from GitHub with:
# install.packages("devtools") devtools::install_github("RamiKrispin/covid19Italy")
While the covid19italy CRAN version is updated every month or two, the Github (Dev) version is updated on a daily bases. The update_data
function enables to overcome this gap and keep the installed version with the most recent data available on the Github version:
library(covid19italy) update_data()
Note: must restart the R session to have the updates available
data(italy_total) head(italy_total)
library(plotly) plot_ly(data = italy_total, x = ~ date, y = ~home_confinement, name = 'Home Confinement', fillcolor = '#FDBBBC', type = 'scatter', mode = 'none', stackgroup = 'one') %>% add_trace( y = ~ hospitalized_with_symptoms, name = "Hospitalized with Symptoms", fillcolor = '#E41317') %>% add_trace(y = ~intensive_care, name = 'Intensive Care', fillcolor = '#9E0003') %>% layout(title = "Italy - Distribution of Active Covid19 Cases", legend = list(x = 0.8, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Source: Italy Department of Civil Protection"))
library(plotly) p <- plot_ly(data = italy_total, x = ~ date, y = ~home_confinement, name = 'Home Confinement', fillcolor = '#FDBBBC', type = 'scatter', mode = 'none', stackgroup = 'one') %>% add_trace( y = ~ hospitalized_with_symptoms, name = "Hospitalized with Symptoms", fillcolor = '#E41317') %>% add_trace(y = ~intensive_care, name = 'Intensive Care', fillcolor = '#9E0003') %>% layout(title = "Italy - Distribution of Active Covid19 Cases", legend = list(x = 0.8, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Source: Italy Department of Civil Protection")) orca(p, "man/figures/positive_dist.svg")
plot_ly(data = italy_total, x = ~ date, y = ~ cumulative_positive_cases, name = 'Active', fillcolor = '#1f77b4', type = 'scatter', mode = 'none', stackgroup = 'one') %>% add_trace( y = ~ death, name = "Death", fillcolor = '#E41317') %>% add_trace(y = ~recovered, name = 'Recovered', fillcolor = 'forestgreen') %>% layout(title = "Italy - Distribution of Covid19 Cases", legend = list(x = 0.1, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Source: Italy Department of Civil Protection"))
p <- plot_ly(data = italy_total, x = ~ date, y = ~ cumulative_positive_cases, name = 'Active', fillcolor = '#1f77b4', type = 'scatter', mode = 'none', stackgroup = 'one') %>% add_trace( y = ~ death, name = "Death", fillcolor = '#E41317') %>% add_trace(y = ~recovered, name = 'Recovered', fillcolor = 'forestgreen') %>% layout(title = "Italy - Distribution of Covid19 Cases", legend = list(x = 0.1, y = 0.9), yaxis = list(title = "Number of Cases"), xaxis = list(title = "Source: Italy Department of Civil Protection")) orca(p, "man/figures/case_dist.svg")
italy_region %>% filter(date == max(date)) %>% select(region_name, cumulative_positive_cases, recovered, death, cumulative_cases) %>% arrange(-cumulative_cases) %>% mutate(region = factor(region_name, levels = region_name)) %>% plot_ly(y = ~ region, x = ~ cumulative_positive_cases, orientation = 'h', text = ~ cumulative_positive_cases, textposition = 'auto', type = "bar", name = "Active", marker = list(color = "#1f77b4")) %>% add_trace(x = ~ recovered, text = ~ recovered, textposition = 'auto', name = "Recovered", marker = list(color = "forestgreen")) %>% add_trace(x = ~ death, text = ~ death, textposition = 'auto', name = "Death", marker = list(color = "red")) %>% layout(title = "Cases Distribution by Region", barmode = 'stack', yaxis = list(title = "Region"), xaxis = list(title = "Number of Cases"), hovermode = "compare", legend = list(x = 0.65, y = 0.9), margin = list( l = 20, r = 10, b = 10, t = 30, pad = 2 ))
``` {r include=FALSE} library(dplyr)
p <- italy_region %>% filter(date == max(date)) %>% select(region_name, cumulative_positive_cases, recovered, death, cumulative_cases) %>% arrange(-cumulative_cases) %>% mutate(region = factor(region_name, levels = region_name)) %>% plot_ly(y = ~ region, x = ~ cumulative_positive_cases, orientation = 'h', text = ~ cumulative_positive_cases, textposition = 'auto', type = "bar", name = "Active", marker = list(color = "#1f77b4")) %>% add_trace(x = ~ recovered, text = ~ recovered, textposition = 'auto', name = "Recovered", marker = list(color = "forestgreen")) %>% add_trace(x = ~ death, text = ~ death, textposition = 'auto', name = "Death", marker = list(color = "red")) %>% layout(title = "Cases Distribution by Region", barmode = 'stack', yaxis = list(title = "Region"), xaxis = list(title = "Number of Cases"), hovermode = "compare", legend = list(x = 0.65, y = 0.9), margin = list( l = 20, r = 10, b = 10, t = 30, pad = 2 ))
orca(p, "man/figures/region_bar_plot.svg")
<img src="man/figures/region_bar_plot.svg" width="100%" /> ### Cases distribution by province for Lombardia region ```r italy_province %>% filter(date == max(date), region_name == "Lombardia") %>% plot_ly(labels = ~province_name, values = ~total_cases, textinfo="label+percent", type = 'pie') %>% layout(title = "Lombardia - Cases Distribution by Province") %>% hide_legend()
``` {r include=FALSE} library(dplyr) p <- italy_province %>% filter(date == max(date), region_name == "Lombardia") %>% plot_ly(labels = ~province_name, values = ~total_cases, textinfo="label+percent", type = 'pie') %>% layout(title = "Lombardia - Cases Distribution by Province") %>% hide_legend()
orca(p, "man/figures/province_pie.svg") ```
A supporting dashboard for the covid19italy datasets available here.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.