# Introduction to the covid19tunisia package

The covid19tunisia R package provides a tidy format dataset of the 2019 Novel Coronavirus COVID-19 (2019-nCoV) pandemic outbreak in Tunisia. The package covers a daily summary of the outbreak on the national level.

The data was pull from :

- Official Facebook page of the Tunisian Ministry of Health through their daily published press releases.

- National Observatory of New and Emerging Diseases

- Regional governments in Tunisia.

## Installation

You can install the released version of covid19tunisia from CRAN with:

    install.packages("covid19tunisia")

## Overview

The `covid19tunisia` dataset provides an overall summary of the cases in Tunisia since the beginning of the covid19 outbreak on March 2, 2020. The dataset contains the following fields:

▲ `date` - The date in YYYY-MM-DD form.

▲ `location` - The name of the government as provided by the data sources.

▲ `location_type` - The type of location using the covid19R controlled vocabulary. In this case, it’s “state”.

▲ `location_code` - A standardized location code using a national or international standard. In this case, . See https://www.iso.org/obp/ui/#iso:code:3166:TN for details.

▲ `location_code_type` The type of standardized location code being used according to the covid19R controlled vocabulary. Here we use “ISO 3166-2”.

▲ `data_type` - the type of data in that given row. Includes cases new : new confirmed Covid-19 cases during on the current date, recovered_new : new number of patients recovered on the current date and deaths_new : new deaths on the current date.

▲ `value` - number of cases of each data type.

    library(covid19tunisia)

    data <- refresh_covid19tunisia()
    #> Downloading raw data from https://raw.githubusercontent.com/MounaBelaid/covid19datatunisia/master/dist/data.csv.

    head(data)
    #> # A tibble: 6 × 7
    #>   date       location location_type location_code location_code_type data_type
    #>   <date>     <chr>    <chr>         <chr>         <chr>              <chr>
    #> 1 2020-03-02 Gafsa    state         TN-71         iso_3166_2         cases_new
    #> 2 2020-03-08 Mahdia   state         TN-53         iso_3166_2         cases_new
    #> 3 2020-03-09 Bizerte  state         TN-23         iso_3166_2         cases_new
    #> 4 2020-03-09 Mahdia   state         TN-53         iso_3166_2         cases_new
    #> 5 2020-03-09 Tunis    state         TN-11         iso_3166_2         cases_new
    #> 6 2020-03-10 Mahdia   state         TN-53         iso_3166_2         cases_new
    #> # ℹ 1 more variable: value <dbl>

    str(data)
    #> spc_tbl_ [5,298 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
    #>  $ date              : Date[1:5298], format: "2020-03-02" "2020-03-08" ...
    #>  $ location          : chr [1:5298] "Gafsa" "Mahdia" "Bizerte" "Mahdia" ...
    #>  $ location_type     : chr [1:5298] "state" "state" "state" "state" ...
    #>  $ location_code     : chr [1:5298] "TN-71" "TN-53" "TN-23" "TN-53" ...
    #>  $ location_code_type: chr [1:5298] "iso_3166_2" "iso_3166_2" "iso_3166_2" "iso_3166_2" ...
    #>  $ data_type         : chr [1:5298] "cases_new" "cases_new" "cases_new" "cases_new" ...
    #>  $ value             : num [1:5298] 1 1 1 1 1 1 1 3 3 1 ...
    #>  - attr(*, "spec")=
    #>   .. cols(
    #>   ..   date = col_date(format = ""),
    #>   ..   location = col_character(),
    #>   ..   location_type = col_character(),
    #>   ..   location_code = col_character(),
    #>   ..   location_code_type = col_character(),
    #>   ..   data_type = col_character(),
    #>   ..   value = col_double()
    #>   .. )
    #>  - attr(*, "problems")=<externalptr>

### Plotting the daily evolution of active cases

    # Transform the data

    library(dplyr)
    library(tidyr)
    library(plotly)

    data_transformed <- data %>% group_by(date,data_type) %>% summarise(value=sum(value)) %>%
                        spread(data_type,value)

    head(data_transformed)
    # A tibble: 6 x 4
    # Groups:   date [6]
      date       cases_new deaths_new recovered_new
      <date>         <dbl>      <dbl>         <dbl>
    1 2020-03-02         1          0             0
    2 2020-03-08         1          0             0
    3 2020-03-09         3          0             0
    4 2020-03-10         1          0             0
    5 2020-03-11         1          0             0
    6 2020-03-12         6          0             0

      data_transformed %>%
      ungroup() %>% plot_ly(type = 'scatter',
                            mode = 'lines+markers')%>%
      add_trace(x = ~date, y = ~cumsum(cases_new),
                name = 'Confirmed cases',
                marker = list(color = '#fec44f'),
                line = list(color = '#fec44f'),
                hoverinfo = "text",
                text = ~paste(cases_new, "New confirmed cases\n",cumsum(cases_new), 'Total number of infected cases on', date)) %>%
      add_trace(x = ~date, y = ~cumsum(deaths_new),
                name = 'Deaths',
                marker = list(color = 'red'),
                line = list(color = 'red'),
                hoverinfo = "text",
                text = ~paste(deaths_new, "New deaths\n",cumsum(deaths_new), 'Total number of deaths on', date)) %>%
      add_trace(x = ~date, y = ~cumsum(recovered_new),
                name = 'Recovered cases',
                marker = list(color = 'green'),
                line = list(color = 'green'),
                hoverinfo = "text",
                text = ~paste(recovered_new, "New recovered cases\n",cumsum(recovered_new), 'Total number of recovered cases on', date)) %>%
      layout(title = 'Tunisia - Daily Evolution of Active COVID19 Cases',
             legend = list(x = 0.1, y = 0.9,
                           font = list(family = "sans-serif", size = 14, color = "#000"), bgcolor = "",
                           bordercolor = "#FFFFFF", borderwidth = 2),
             xaxis = list(title = ""),
             yaxis = list(side = 'left', title = 'Daily evolution', showgrid = TRUE, zeroline = TRUE))