-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
93 lines (75 loc) · 2.66 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# epidatasets
<!-- badges: start -->
[](https://github.com/cmu-delphi/epidatasets/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
This package contains data sets used to compile vignettes
and other documentation in Delphi R Packages. The goal is to
avoid calls to the Delphi Epidata API, and deposit some
examples here for easy offline use.
## Installation
You can install the development version of `{epidatasets}` like so:
``` r
# install.packages("pak")
pak::pkg_install("cmu-delphi/epidatasets")
```
## Contents
This package contains a number of different datasets, along
with the code used to generate them. See the Source Code if
you want to examine the necessary API calls.
All data included here is in `epi_df` format, which is a
subclass of `tbl_df` which is a subclass of `data.frame`.
The data will print nicely if you load the `{epiprocess}`
or `{tibble}` packages, but these are not required to access
or inspect the data sets. For example,
```{r}
library(epidatasets)
head(cases_deaths_subset)
```
Compared to
```{r}
library(tibble)
cases_deaths_subset
```
Compared to
```{r, message=FALSE}
library(epiprocess)
cases_deaths_subset
```
Note that an `epi_df` comes with metadata (visible in that
final version), that describes the observation frequency,
`time_type`, the unit of geographical measurement, `geo_type`
and the data vintage, `as_of`. For more on these, see the
`{epiprocess}`.
For the more visually inclined, that particular data set contains
reported 7-day averaged cases and deaths per capita for a
handful of US states.
```{r, echo=FALSE, message=FALSE, dev='svg'}
library(ggplot2)
lab = c(case_rate_7d_av = "Weekly-average cases per 100K inhabitants",
death_rate_7d_av = "Weekly-average deaths per 100K inhabitants")
cases_deaths_subset |>
dplyr::select(geo_value:death_rate_7d_av) |>
tidyr::pivot_longer(case_rate_7d_av:death_rate_7d_av) |>
ggplot(aes(time_value, value, colour = geo_value)) +
geom_line() +
scale_x_date(name = "", date_labels = "%b %Y") +
scale_y_continuous(name = "", expand = expansion(c(0, 0.05))) +
facet_wrap(~ name, scales = "free_y", nrow = 2,
labeller = labeller(name = lab)) +
theme_bw() +
guides(colour = guide_legend(nrow = 1)) +
scale_color_brewer(palette = "Set1") +
theme(legend.position = "bottom", legend.title = element_blank())
```