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) <- covidcast_signal(data_source = "indicator-combination", comb 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 15 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
<- covidcast_signal(data_source = "usa-facts", inum 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 15 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
plot method for
plot.covidcast_signal(), produces choropleth maps by using
ggplot2 and the
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")
colors, we can create custom color scales, for example to have a log-spaced color scale for incident case counts:
<- c(0, 1, 2, 5, 10, 20, 50, 100, 200) breaks <- c("#D3D3D3", "#FFFFCC", "#FEDDA2", "#FDBB79", "#FD9950", "#EB7538", colors "#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 = -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?
<- covidcast_signal(data_source = "usa-facts", cprop signal = "confirmed_cumulative_prop", start_day = "2020-07-01", end_day = "2020-07-14") <- c(0, 1000) breaks <- c("#D3D3D3", "#FFC0CB") colors plot(cprop, choro_col = colors, choro_params = list(breaks = breaks, legend_width = 3), title = "Cumulative COVID cases per 100k people on 2020-07-14")
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.