knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(asymptor)
Let's start by loading the example data. It's bundled in the package but originally comes from https://github.com/GoogleCloudPlatform/covid-19-open-data (Apache License 2.0).
df <- readRDS(system.file("extdata", "covid19_italy.rds", package = "asymptor")) head(df)
We can feed this data directly to the estimate_asympto()
function. This
function requires 3 columns, labelled as date
, new_cases
, new_deaths
,
containing the daily counts (not the cumulated total!)
asy <- estimate_asympto(df$date, df$new_cases, df$new_deaths) head(asy)
We may want to visualise these estimations alongside the empirical data. So, we start by merging the two datasets:
res <- merge(df, asy) head(res)
Alternatively, we can directly use a tidyverse-compatible syntax:
library(dplyr) res <- df %>% mutate(lower = estimate_asympto(date, new_cases, new_deaths, "lower")$lower, upper = estimate_asympto(date, new_cases, new_deaths, "upper")$upper) head(res)
Then, we can the ggplot2 package to plot the result:
library(ggplot2) ggplot(res, aes(x = date)) + geom_line(aes(y = new_cases+lower), col = "grey30") + geom_ribbon(aes(ymin = new_cases+lower, ymax = new_cases+upper), fill = "grey30") + geom_line(aes(y = new_cases), color = "red") + labs(title = "Estimated total vs detected cases of COVID-19 in Italy", y = "Cases") + theme_minimal()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.