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 doctor visits signal as an example; it records the percentage of outpatient doctor visits with COVID symptom codes, as reported by Delphi’s health system partners. We’ll also use incident case counts. Fetching the data is simple:

library(covidcast)

dv <- covidcast_signal(data_source = "doctor-visits",
                       signal = "smoothed_adj_cli",
                       start_day = "2020-07-01", end_day = "2020-07-14")
summary(dv)
## A `covidcast_signal` dataframe with 28450 rows and 15 columns.
## 
## data_source : doctor-visits
## signal      : smoothed_adj_cli
## geo_type    : county
## 
## first date                          : 2020-07-01
## last date                           : 2020-07-14
## median number of geo_values per day : 2035
inum <- covidcast_signal(data_source = "jhu-csse",
                         signal = "confirmed_7dav_incidence_prop",
                         start_day = "2020-07-01", end_day = "2020-07-14")
summary(inum)
## A `covidcast_signal` dataframe with 45864 rows and 15 columns.
## 
## data_source : jhu-csse
## signal      : confirmed_7dav_incidence_prop
## geo_type    : county
## 
## first date                          : 2020-07-01
## last date                           : 2020-07-14
## median number of geo_values per day : 3276

Choropleth maps

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

plot(dv)

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(dv, time_value = "2020-07-04", choro_col = cm.colors(10), alpha = 0.4,
     title = "COVID doctor visits 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")