|
| 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 | +``` |
0 commit comments