Skip to content

Commit 514025a

Browse files
authored
Merge pull request #133 from benjaminysmith/main
Add Quidel, Doctor Visits, Hospital Admissions, GHT R dashboards to the example notebooks
2 parents 4e462ed + 3aeca61 commit 514025a

File tree

6 files changed

+341
-1
lines changed

6 files changed

+341
-1
lines changed

R-notebooks/dashboard_functions.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
make_covidcast_signal <- function(destination, source, geo_type) {
2+
destination$time_value = source$time_value[1]
3+
destination$issue = source$issue[1]
4+
attributes(destination)$geo_type = geo_type
5+
class(destination) = c("covidcast_signal", "data.frame")
6+
return(destination)
7+
}
8+
9+
plot_28_day_frequency_state <- function(df_to_plot) {
10+
states_present = df_to_plot %>%
11+
group_by(geo_value) %>%
12+
summarize(value = n())
13+
14+
covidcast_signal_to_plot = make_covidcast_signal(states_present, df_to_plot, "state")
15+
16+
plot(covidcast_signal_to_plot,
17+
title = sprintf(
18+
"State frequency in last 28 days (start date: %s)",
19+
covidcast_signal_to_plot$time_value[1]
20+
),
21+
range = c(0, 28))
22+
}
23+
24+
plot_28_day_frequency_county <- function(df_to_plot) {
25+
counties_present = df_to_plot %>%
26+
group_by(geo_value) %>%
27+
summarize(value = n()) %>% ungroup() %>%
28+
filter(substr(geo_value, 3, 5) != "000")
29+
30+
covidcast_signal_to_plot = make_covidcast_signal(counties_present, df_to_plot, "county")
31+
32+
plot(
33+
covidcast_signal_to_plot,
34+
title = sprintf(
35+
"County frequency in last 28 days (start date: %s)",
36+
covidcast_signal_to_plot$time_value[1]
37+
),
38+
range = c(0, 28)
39+
)
40+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "Doctor Visits dashboard"
3+
author: "Delphi Lab"
4+
date: "`r format(Sys.time(), '%B %d, %Y')`"
5+
output:
6+
html_document:
7+
code_folding: hide
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
12+
```
13+
14+
### Coverage
15+
16+
This measures how much county coverage we have in the samples (i.e., how many unique counties are present each day), and how it has recently changed over time.
17+
18+
```{r, fig.width = 7, fig.height = 5}
19+
20+
library(covidcast)
21+
library(dplyr)
22+
library(ggplot2)
23+
24+
date_scale <-
25+
scale_x_date(date_breaks = "1 week", date_labels = "%b %d")
26+
27+
twenty_eight_days_ago = Sys.Date() - 28
28+
29+
# Sampling coverage
30+
df_doctor_visits_counties = covidcast_signal("doctor-visits",
31+
"smoothed_cli",
32+
start_day = twenty_eight_days_ago,
33+
geo_type = "county")
34+
counties_per_day = df_doctor_visits_counties %>%
35+
group_by(time_value) %>%
36+
summarize(n = n())
37+
38+
ggplot(counties_per_day, aes(x = time_value, y = n)) +
39+
geom_line() + geom_point() + theme_bw() +
40+
labs(
41+
x = "Date",
42+
y = "Number of Counties",
43+
title = sprintf(
44+
"Unique Counties: %i, mean per day: %i",
45+
length(unique(df_doctor_visits_counties$geo_value)),
46+
round(mean(counties_per_day$n))
47+
)
48+
) + date_scale
49+
```
50+
51+
## County Coverage Map
52+
53+
This visualizes the county coverage -- how frequently does each county show up in the data over the last 28 days?
54+
55+
```{r, fig.width = 10, fig.height = 8}
56+
57+
source("dashboard_functions.R")
58+
plot_28_day_frequency_county(df_doctor_visits_counties)
59+
```

R-notebooks/ght_dashboard.Rmd

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: "Google Health Trends dashboard"
3+
author: "Delphi Lab"
4+
date: "`r format(Sys.time(), '%B %d, %Y')`"
5+
output:
6+
html_document:
7+
code_folding: hide
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
12+
```
13+
14+
### Response Volume
15+
16+
This is a check on overall volume of raw results. There may be weekly effects but we would not expect to see any big systematic changes.
17+
18+
```{r, fig.width = 7, fig.height = 5}
19+
library(covidcast)
20+
library(dplyr)
21+
library(ggplot2)
22+
23+
date_scale <-
24+
scale_x_date(
25+
date_breaks = "1 month",
26+
date_minor_breaks = "1 week",
27+
date_labels = "%b %Y"
28+
)
29+
30+
twenty_eight_days_ago = Sys.Date() - 28
31+
32+
# Sampling volume
33+
df_ght_states = covidcast_signal("ght",
34+
"raw_search",
35+
start_day = twenty_eight_days_ago,
36+
geo_type = "state")
37+
n_per_day = df_ght_states %>%
38+
group_by(time_value) %>%
39+
summarize(n = sum(value))
40+
41+
ggplot(n_per_day, aes(x = time_value, y = n)) +
42+
geom_line() + geom_point() + theme_bw() +
43+
labs(
44+
x = "Date",
45+
y = "Total search volume (arbitrary units)",
46+
title = sprintf("Mean per day: %i",
47+
round(sum(n_per_day$n)), round(mean(n_per_day$n)))
48+
) +
49+
date_scale
50+
```
51+
52+
### Coverage
53+
54+
This measures how much state coverage we have in the samples (i.e., how many unique states are present each day), and how it has recently changed over time.
55+
56+
```{r, fig.width = 7, fig.height = 5}
57+
# Sampling coverage
58+
df_ght_states = covidcast_signal("ght",
59+
"raw_search",
60+
start_day = twenty_eight_days_ago,
61+
geo_type = "state")
62+
states_per_day = df_ght_states %>%
63+
group_by(time_value) %>%
64+
summarize(n = n())
65+
66+
ggplot(states_per_day, aes(x = time_value, y = n)) +
67+
geom_line() + geom_point() + theme_bw() +
68+
labs(
69+
x = "Date",
70+
y = "Number of States",
71+
title = sprintf(
72+
"Unique States: %i, mean per day: %i",
73+
length(unique(df_ght_states$geo_value)),
74+
round(mean(states_per_day$n))
75+
)
76+
) +
77+
date_scale
78+
```
79+
80+
## State Coverage Map
81+
82+
This visualizes the state coverage -- how frequently does each state show up in the data over the last 28 days?
83+
84+
```{r, fig.width = 10, fig.height = 8}
85+
86+
source("dashboard_functions.R")
87+
plot_28_day_frequency_state(df_ght_states)
88+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "Hospital Admissions dashboard"
3+
author: "Delphi Lab"
4+
date: "`r format(Sys.time(), '%B %d, %Y')`"
5+
output:
6+
html_document:
7+
code_folding: hide
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
12+
```
13+
14+
```{r}
15+
library(covidcast)
16+
library(dplyr)
17+
library(ggplot2)
18+
19+
date_scale <-
20+
scale_x_date(date_breaks = "1 week", date_labels = "%b %d")
21+
22+
twenty_eight_days_ago = Sys.Date() - 28
23+
```
24+
25+
26+
### Coverage
27+
28+
This measures how much county coverage we have in the samples (i.e., how many unique counties are present each day), and how it has recently changed over time.
29+
30+
```{r, fig.width = 7, fig.height = 5}
31+
32+
# Sampling coverage
33+
df_hospital_admissions_counties = covidcast_signal(
34+
"hospital-admissions",
35+
"smoothed_covid19_from_claims",
36+
start_day = twenty_eight_days_ago,
37+
geo_type = "county"
38+
)
39+
counties_per_day = df_hospital_admissions_counties %>%
40+
group_by(time_value) %>%
41+
summarize(n = n())
42+
43+
ggplot(counties_per_day, aes(x = time_value, y = n)) +
44+
geom_line() + geom_point() + theme_bw() +
45+
labs(
46+
x = "Date",
47+
y = "Number of Counties",
48+
title = sprintf(
49+
"Unique Counties: %i, mean per day: %i",
50+
length(unique(
51+
df_hospital_admissions_counties$geo_value
52+
)),
53+
round(mean(counties_per_day$n))
54+
)
55+
) + date_scale
56+
```
57+
58+
## County Coverage Map
59+
60+
This visualizes the county coverage -- how frequently does each county show up in the data over the last 28 days?
61+
62+
```{r, fig.width = 10, fig.height = 8}
63+
64+
source("dashboard_functions.R")
65+
plot_28_day_frequency_county(df_hospital_admissions_counties)
66+
```

R-notebooks/make.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
file_names = list.files(".", pattern="*.Rmd")
22
file_names = substr(file_names, 1, nchar(file_names)-4)
33

4-
file_name = "fb_dashboard"
54
for (file_name in file_names) {
65
cat(sprintf("Rendering %s ... ", file_name))
76
t0 = proc.time()

R-notebooks/quidel_dashboard.Rmd

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: "Quidel dashboard"
3+
author: "Delphi Lab"
4+
date: "`r format(Sys.time(), '%B %d, %Y')`"
5+
output:
6+
html_document:
7+
code_folding: hide
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(message = FALSE, warning = FALSE)
12+
```
13+
14+
### Response Volume
15+
16+
This is a check on overall volume of raw results. There may be weekly effects but we would not expect to see any big systematic changes.
17+
18+
```{r, fig.width = 7, fig.height = 5}
19+
library(covidcast)
20+
library(dplyr)
21+
library(ggplot2)
22+
23+
date_scale <-
24+
scale_x_date(
25+
date_breaks = "1 month",
26+
date_minor_breaks = "1 week",
27+
date_labels = "%b %Y"
28+
)
29+
30+
twenty_eight_days_ago = Sys.Date() - 28
31+
32+
# Sampling volume
33+
df_quidel_states = covidcast_signal("quidel",
34+
"covid_ag_raw_pct_positive",
35+
start_day = twenty_eight_days_ago,
36+
geo_type = "state")
37+
n_per_day = df_quidel_states %>%
38+
group_by(time_value) %>%
39+
summarize(n = sum(sample_size))
40+
41+
ggplot(n_per_day, aes(x = time_value, y = n)) +
42+
geom_line() + geom_point() + theme_bw() +
43+
labs(
44+
x = "Date",
45+
y = "Number of Responses",
46+
title = sprintf("Total responses: %i, mean per day: %i",
47+
round(sum(n_per_day$n)), round(mean(n_per_day$n)))
48+
) +
49+
date_scale
50+
```
51+
52+
### Coverage
53+
54+
This measures how much state coverage we have in the samples (i.e., how many unique states are present each day), and how it has recently changed over time.
55+
56+
```{r, fig.width = 7, fig.height = 5}
57+
# Sampling coverage
58+
df_quidel_states = covidcast_signal("quidel",
59+
"covid_ag_raw_pct_positive",
60+
start_day = twenty_eight_days_ago,
61+
geo_type = "state")
62+
states_per_day = df_quidel_states %>%
63+
group_by(time_value) %>%
64+
summarize(n = n())
65+
66+
ggplot(states_per_day, aes(x = time_value, y = n)) +
67+
geom_line() + geom_point() + theme_bw() +
68+
labs(
69+
x = "Date",
70+
y = "Number of States",
71+
title = sprintf(
72+
"Unique States: %i, mean per day: %i",
73+
length(unique(df_quidel_states$geo_value)),
74+
round(mean(states_per_day$n))
75+
)
76+
) +
77+
date_scale
78+
```
79+
80+
## State Coverage Map
81+
82+
This visualizes the state coverage -- how frequently does each state show up in the data over the last 28 days?
83+
84+
```{r, fig.width = 10, fig.height = 8}
85+
86+
source("dashboard_functions.R")
87+
plot_28_day_frequency_state(df_quidel_states)
88+
```

0 commit comments

Comments
 (0)