-
Notifications
You must be signed in to change notification settings - Fork 1
/
uhs.Rmd
85 lines (76 loc) · 2.14 KB
/
uhs.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
---
title: "UHS Testing Results"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE,
fig.height = 3, fig.width = 7)
```
```{r}
library(tidyverse)
#library(googledrive)
library(googlesheets4)
library(RcppRoll)
```
```{r eval=FALSE}
# do this once to authorize within google drive
drive_auth("[email protected]")
gs4_auth(token = drive_token())
```
```{r eval=FALSE}
# do this once to authorize within google sheets
gs4_auth(email = "[email protected]",
scopes = "https://www.googleapis.com/auth/spreadsheets.readonly")
```
```{r}
roll7 <- function(x) {
x <- roll_mean(x, 7)
c(rep(x[1], 6), x)
}
uhs <- scan("data/uhs.txt", "char")
uhs <- read_sheet(uhs,
sheet = "COVID-data")
uhs <- uhs %>%
select(Date_of_results:Facstaff_positives) %>%
rename(
Date = "Date_of_results",
student_total = "Student_total_tests",
student_positive = "Student_positives",
facstaff_total = "Facstaff_total_tests",
facstaff_positive = "Facstaff_positives") %>%
filter(!is.na(student_total)) %>%
mutate(Date = as.POSIXct(Date)) %>%
pivot_longer(student_total:facstaff_positive, names_to = "group", values_to = "value") %>%
mutate(count_type = str_remove(group, ".*_"),
group = str_remove(group, "_.*")) %>%
pivot_wider(names_from = "count_type", values_from = "value") %>%
group_by(group) %>%
mutate(cum_pos = cumsum(positive),
cum_total = cumsum(total),
roll_pos = roll7(positive),
roll_total = roll7(total),
cum_pct = 100 * cum_pos / cum_total,
roll_pct = 100 * roll_pos / roll_total) %>%
ungroup()
```
```{r}
ggplot(uhs) +
aes(Date, positive, col = group) +
geom_point() +
geom_path(linetype = "dashed") +
geom_path(aes(y=roll_pos), size = 2) +
ylab("Number Positive")
```
```{r}
ggplot(uhs) +
aes(Date, roll_pct, col = group) +
geom_path(size = 2) +
ylab("Percent Positive (7-day rolling mean)")
```
```{r}
ggplot(uhs) +
aes(Date, cum_pos, col = group) +
geom_path(size = 2) +
ylab("Cumulative Number Positive")
```