knitr::opts_chunk$set(echo = TRUE)
library('ff')
library('covid19Visualizer')
library('kableExtra')
library('DBI')
library('here')

Introduction

Simple data visualizer for COVID-19 diffusion.

Data

Database

Data is provided by Our world in data and is obtained from https://covid.ourworldindata.org/data/owid-covid-data.xlsx.

New data is obtained with updateDb() (a network connection is required).

We can explore the database using the rsqlite/DBI package'

# connec to the database
con <- createConnection()

# get tables
dbListTables(con)

# get fields in a table
dbListFields(con, "events")

# close database connection
dbDisconnect(con)
library(covid19Visualizer)

con <- createConnection()

metric <- c('new_cases')
multiplyFactor <- 1e6
date <- NULL

# group and no norm, plot
countries <- NULL
groups <- 'Asia'
normBy <- NULL

events <- getEventsDb(con, groups, countries, date, metric)
events <- aggregateCountries(con, events, groups)
doPlot(events)


# group and norm, plot
countries <- NULL
groups <- 'Asia'
normBy <- 'population'

population <- getPopulationDb(con, groups, countries)
events <- getEventsDb(con, groups, countries, date, metric)
events <- aggregateCountries(con, events, groups)
population <- aggregateCountries(con, population, groups)
events <- normaliseEvents(events,
                          population,
                          normBy,
                          multiplyFactor)

doPlot(events)


# country and no norm, plot
countries <- c('Canada', 'Italy')
groups <- NULL
normBy <- NULL

events <- getEventsDb(con, groups, countries, date, metric)
doPlot(events)


# country and norm, plot
countries <- c('Canada', 'Italy')
groups <- NULL
normBy <- 'population'

population <- getPopulationDb(con, groups, countries)
events <- getEventsDb(con, groups, countries, date, metric)
events <- normaliseEvents(events,
                          population,
                          normBy,
                          multiplyFactor)
doPlot(events)


# group and no norm, map
countries <- NULL
groups <- 'Asia'
normBy <- NULL

events <- getEventsDb(con, groups, countries, date, metric)
events <- getMapData(con, events)
doMap(events, FALSE)


# group and norm, map
countries <- NULL
groups <- 'Asia'
normBy <- 'population'

population <- getPopulationDb(con, groups, countries)
events <- getEventsDb(con, groups, countries, date, metric)
events <- normaliseEvents(events,
                          population,
                          normBy,
                          multiplyFactor)
events <- getMapData(con, events)
doMap(events, FALSE)


# country and no norm, map
countries <- c('Canada', 'Italy')
groups <- NULL
normBy <- NULL

events <- getEventsDb(con, groups, countries, date, metric)
events <- getMapData(con, events)
doMap(events, TRUE)


# country and norm, map
countries <- c('Canada', 'Italy')
groups <- NULL
normBy <- 'population'

population <- getPopulationDb(con, groups, countries)
events <- getEventsDb(con, groups, countries, date, metric)
events <- normaliseEvents(events,
                          population,
                          normBy,
                          multiplyFactor)
events <- getMapData(con, events)
doMap(events, TRUE)

Make Predictions

metric <- c('new_cases_smoothed', 'total_vaccinations')
date <- NULL

# group and no norm, plot
countries <- c('Canada', 'Italy')
groups <- NULL
normBy <- NULL

events <- getEventsDb(con, groups, countries, date, metric)

predictions <- predict_data(events,days_predict = 60, training_window = 14)
doPlot(predictions, TRUE)

Plot population

This plot does not have y axis because metrics are normalised between 0 and 1 so that they can be visualised even when massively different (i.e. population and age). It is advised to display the plot using plotly: ggplotly(p, tooltip = 'text') to get more information from the tooltip.

countries <- c('Canada', 'Italy')
groups <- NULL
population <- getPopulationDb(con, groups, countries)
populationPlot(population,
               c('aged_65_older',
                 'aged_70_older',
                 'population'))


countries <- NULL
groups <- c('Europe', 'North America')
population <- getPopulationDb(con, groups, countries)
population <- aggregateCountries(con, population, groups)
populationPlot(population,
               c('aged_65_older',
                 'aged_70_older',
                 'population'))

Last update r Sys.Date().



theasjblog/covid19_package documentation built on May 2, 2021, 8:11 p.m.