Skip to content

Commit b529fbd

Browse files
authored
Merge pull request #216 from sarah-colq/main
Add HRR and MSA to choropleth plots
2 parents 5ed7210 + ac9b98b commit b529fbd

32 files changed

+2986
-25
lines changed

.github/workflows/r_ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ jobs:
3030
uses: r-lib/actions/setup-r@v1
3131
with:
3232
r-version: ${{ matrix.r-version }}
33-
- name: Install libcurl
34-
run: sudo apt-get install libcurl4-openssl-dev
33+
- name: Install linux dependencies
34+
run: |
35+
sudo apt-get install libcurl4-openssl-dev
36+
sudo apt-get install libudunits2-dev
37+
sudo apt-get install libgdal-dev
3538
- name: Cache R packages
3639
uses: actions/cache@v2
3740
with:

R-notebooks/dashboard_functions.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ plot_28_day_frequency_state <- function(df_to_plot) {
1313

1414
covidcast_signal_to_plot = make_covidcast_signal(states_present, df_to_plot, "state")
1515

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))
16+
plot(
17+
covidcast_signal_to_plot,
18+
title = sprintf(
19+
"State frequency in last 28 days (start date: %s); grey = no data for state.",
20+
covidcast_signal_to_plot$time_value[1]
21+
),
22+
range = c(1, 28),
23+
choro_params = list(legend_digits = 0)
24+
)
2225
}
2326

2427
plot_28_day_frequency_county <- function(df_to_plot) {
@@ -32,9 +35,10 @@ plot_28_day_frequency_county <- function(df_to_plot) {
3235
plot(
3336
covidcast_signal_to_plot,
3437
title = sprintf(
35-
"County frequency in last 28 days (start date: %s)",
38+
"County frequency in last 28 days (start date: %s); grey = no data for county.",
3639
covidcast_signal_to_plot$time_value[1]
3740
),
38-
range = c(0, 28)
41+
range = c(1, 28),
42+
choro_params = list(legend_digits = 0)
3943
)
4044
}

R-notebooks/jhu_dashboard.Rmd

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "JHU 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_jhu_counties = covidcast_signal(
34+
"jhu-csse",
35+
"confirmed_7dav_cumulative_num",
36+
start_day = twenty_eight_days_ago,
37+
geo_type = "county"
38+
)
39+
counties_per_day = df_jhu_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_jhu_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_jhu_counties)
66+
67+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "Safegraph 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_safegraph_counties = covidcast_signal(
34+
"safegraph",
35+
"median_home_dwell_time",
36+
start_day = twenty_eight_days_ago,
37+
geo_type = "county"
38+
)
39+
counties_per_day = df_safegraph_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_safegraph_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_safegraph_counties)
66+
67+
```
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
title: "USA facts 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_usa_facts_counties = covidcast_signal(
34+
"usa-facts",
35+
"confirmed_cumulative_num",
36+
start_day = twenty_eight_days_ago,
37+
geo_type = "county"
38+
)
39+
counties_per_day = df_usa_facts_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_usa_facts_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_usa_facts_counties)
66+
67+
```

R-packages/covidcast/DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Imports:
4646
maptools,
4747
purrr,
4848
rlang,
49+
sf,
4950
tidyr,
5051
usmap
5152
RoxygenNote: 7.1.1

0 commit comments

Comments
 (0)