1. Plotting and mapping signals

Once you’ve fetched some COVIDcast signals using covidcast_signal(), the returned covidcast objects can be plotted and mapped in various ways. The data structure is designed to be tidy and easily wrangled using your favorite packages, but the covidcast package also provides some tools for plotting and mapping signals in an easy way.

For this vignette, we’ll use our combination signal as an example; the combination indicator is a statistical combination of several data sources collected by Delphi, and for every county provides a measure of factors related to COVID activity. We’ll also use incident case counts. Fetching the data is simple:

library(covidcast)

comb <- suppressMessages(
  covidcast_signal(data_source = "indicator-combination",
                   signal = "nmf_day_doc_fbc_fbs_ght",
                   start_day = "2020-07-01", end_day = "2020-07-14")
)
summary(comb)
## A `covidcast_signal` dataframe with 29102 rows and 9 columns.
## 
## data_source : indicator-combination
## signal      : nmf_day_doc_fbc_fbs_ght
## geo_type    : county
## 
## first date                          : 2020-07-01
## last date                           : 2020-07-14
## median number of geo_values per day : 2078
inum <- suppressMessages(
  covidcast_signal(data_source = "usa-facts",
                   signal = "confirmed_7dav_incidence_num",
                   start_day = "2020-07-01", end_day = "2020-07-14")
)
summary(inum)
## A `covidcast_signal` dataframe with 44702 rows and 9 columns.
## 
## data_source : usa-facts
## signal      : confirmed_7dav_incidence_num
## geo_type    : county
## 
## first date                          : 2020-07-01
## last date                           : 2020-07-14
## median number of geo_values per day : 3193

Choropleth maps

The default plot method for covidcast_signal objects, plot.covidcast_signal(), produces choropleth maps by using ggplot2 and the usmap package:

plot(comb)

The color scheme is automatically chosen to be similar to that used on the online COVIDcast mapping tool. Also, by default, this map shows the most recent day of data available in the data frame. One can choose the day and also choose the color scales, transparency level for mega counties, and title:

plot(comb, time_value = "2020-07-04", choro_col = cm.colors(10), alpha = 0.4,
     title = "Combination of COVID-19 indicators on 2020-07-04")

By providing breaks and colors, we can create custom color scales, for example to have a log-spaced color scale for incident case counts:

breaks <- c(0, 1, 2, 5, 10, 20, 50, 100, 200)
colors <- c("#D3D3D3", "#FFFFCC", "#FEDDA2", "#FDBB79", "#FD9950", "#EB7538",
            "#C74E32", "#A3272C", "#800026")

# Note that length(breaks) == length(colors) by design. This works as follows:
# we assign colors[i] iff the value satisfies breaks[i] <= value < breaks[i+1],
# where we take breaks[0] = -Inf and breaks[N+1] = Inf, for N = length(breaks)

plot(inum, choro_col = colors, choro_params = list(breaks = breaks),
     title = "New COVID cases (7-day trailing average) on 2020-07-14")