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:


dv <- covidcast_signal(data_source = "doctor-visits",
                       signal = "smoothed_adj_cli",
                       start_day = "2020-07-01", end_day = "2020-07-14")
## 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")
## 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:


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")

Lastly, we show how we can use custom breaks to (visually) answer the question: which counties have cumulative case rates of at least 1/100?

cprop <- covidcast_signal(data_source = "jhu-csse",
                          signal = "confirmed_cumulative_prop",
                          start_day = "2020-07-01", end_day = "2020-07-14")

breaks <- c(0, 1000)
colors <- c("#D3D3D3", "#FFC0CB")

plot(cprop, choro_col = colors,
     choro_params = list(breaks = breaks, legend_width = 3),
     title = "Cumulative COVID cases per 100k people on 2020-07-14")

Bubble maps

As an alternative to choropleth maps, we can also quickly plot bubble maps. By default, bubble maps have 8 bubble size bins evenly spaced over the range, where zero always means zero bubble size. The legend shows all bins, interpreted as each bubble size meaning at least the corresponding value.

plot(inum, plot_type = "bubble")
## Warning in plot_bubble(x, time_value = time_value, include = include, range =
## range, : Bubble maps can be hard to read when there is missing data;the
## locations without data are filled in gray.