-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathREADME.Rmd
140 lines (107 loc) · 3.4 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# covid19us
<!-- badges: start -->
[](https://travis-ci.org/aedobbyn/covid19us)
[](https://ci.appveyor.com/project/aedobbyn/covid19us)
[](https://app.codecov.io/gh/aedobbyn/covid19us)
[](https://CRAN.R-project.org/package=covid19us)
[](https://opensource.org/licenses/MIT)
<!-- [](https://github.com/metacran/cranlogs.app) -->
<!-- badges: end -->
This is an R wrapper around the [COVID Tracking Project API](https://covidtracking.com/api/). It provides updates on the spread of the virus in the US with a few simple functions.
## Installation
```
install.packages("covid19us")
```
Or the dev version:
```
devtools::install_github("aedobbyn/covid19us")
```
## Examples
```{r example}
library(covid19us)
```
Get the most recent COVID-19 top-line data for the country:
```{r}
get_us_current()
```
Or the same by state:
```{r}
get_states_current()
```
Daily state counts can be filtered by state and/or date:
```{r}
get_states_daily(
state = "NY",
date = "2020-03-17"
)
```
For data in long format:
```{r}
(dat <- refresh_covid19us())
```
Which can be easier to plot
```{r warning=FALSE, message=FALSE}
library(dplyr)
library(ggplot2)
dat %>%
filter(
location == "NY" &
data_type %in%
c(
"positive_increase",
"total_test_results_increase",
"death_increase",
"hospitalized_increase"
)
) %>%
mutate(
Type = data_type %>%
stringr::str_replace_all("_", " ") %>%
stringr::str_to_title()
) %>%
arrange(date) %>%
ggplot(aes(date, value, color = Type)) +
geom_smooth(se = FALSE) +
scale_x_date(date_breaks = "2 weeks") +
labs(title = "COVID in NY") +
xlab("Date") +
ylab("Value") +
theme_minimal(base_family = "Source Sans Pro")
```
To get information about the data:
```{r}
get_info_covid19us()
```
## All Functions
```
get_counties_info
get_info_covid19us
get_states_current
get_states_daily
get_states_info
get_tracker_urls
get_us_current
get_us_daily
refresh_covid19us
```
## Other Details
* All of the data sources can be found with `get_tracker_urls()`
* The `filter` column gives information about how the [COVID Tracking Project's scraper](https://github.com/COVID19Tracking/covid-tracking) currently scrapes data from the page (xpaths, CSS selectors, functions used, etc.)
* State breakdowns include DC as well as some US territories including American Samoa (AS), Guam (GU), Northern Mariana Islands (MP), Puerto Rico (PR), and the Virgin Islands (VI)
* Acronyms
* PUI: persons under investigation
* PUM: persons under monitoring (one step before PUI)
* Time zone used is Eastern Standard Time
***
**[PR](https://github.com/aedobbyn/covid19us/pulls)s and [bug reports / feature requests](https://github.com/aedobbyn/covid19us/issues) welcome.** Stay safe!