You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

7.3 KiB

title: ""
pagetitle: ""
output: rmarkdown::github_document

[![Travis-CI Build Status](](
[![Coverage Status](](

# I M P O R T A N T

The CDC migrated to a new non-Flash portal and back-end APIs changed. This is a complete reimagining of the package and --- as such --- all your code is going to break. Please use GitHub issues to identify previous API functionality you would like ported over. There's a [release candidate for 0.5.2]( which uses the old API but it likely to break in the near future given the changes to the hidden API. You can do what with `devtools::install_github("hrbrmstr/cdcfluview", ref="58c172b")`.

All folks providing feedback, code or suggestions will be added to the DESCRIPTION file. Please include how you would prefer to be cited in any issues you file.

If there's a particular data set from that you want and that isn't in the package, please file it as an issue and be as specific as you can (screen shot if possible).

# :mask: cdcfluview

Retrieve U.S. Flu Season Data from the CDC FluView Portal

## Description

The U.S. Centers for Disease Control (CDC) maintains a portal <> for accessing state, regional and national influenza statistics as well as Mortality Surveillance Data. The Flash interface makes it difficult and time-consuming to select and retrieve influenza data. This package provides functions to access the data provided by the portal's underlying API.

## What's Inside The Tin

The following functions are implemented:

- `age_group_distribution`: Age Group Distribution of Influenza Positive Tests Reported by Public Health Laboratories
- `cdc_basemap`: Retrieve CDC U.S. Basemaps
- `geographic_spread`: State and Territorial Epidemiologists Reports of Geographic Spread of Influenza
- `hospitalizations`: Laboratory-Confirmed Influenza Hospitalizations
- `ilinet`: Retrieve ILINet Surveillance Data
- `ili_weekly_activity_indicators`: Retrieve weekly state-level ILI indicators per-state for a given season
- `pi_mortality`: Pneumonia and Influenza Mortality Surveillance
- `state_data_providers`: Retrieve metadata about U.S. State CDC Provider Data
- `surveillance_areas`: Retrieve a list of valid sub-regions for each surveillance area.
- `who_nrevss`: Retrieve WHO/NREVSS Surveillance Data
- `mmwr_week`: Convert a Date to an MMWR day+week+year
- `mmwr_weekday`: Convert a Date to an MMWR weekday
- `mmwr_week_to_date`: Convert an MMWR year+week or year+week+day to a Date object

The following data sets are included:

- `hhs_regions`: HHS Region Table (a data frame with 59 rows and 4 variables)
- `census_regions`: Census Region Table (a data frame with 51 rows and 2 variables)
- `mmwrid_map`: MMWR ID to Calendar Mappings (it is exported & available, no need to use `data()`)

## Installation

```{r eval=FALSE}

```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}

## Usage

```{r message=FALSE, warning=FALSE, error=FALSE}

# current verison

### Age Group Distribution of Influenza Positive Tests Reported by Public Health Laboratories

```{r message=FALSE, warning=FALSE}

### Retrieve CDC U.S. Coverage Map

```{r message=FALSE, warning=FALSE}

### State and Territorial Epidemiologists Reports of Geographic Spread of Influenza

```{r message=FALSE, warning=FALSE}

### Laboratory-Confirmed Influenza Hospitalizations

```{r message=FALSE, warning=FALSE, fig.width=10, fig.height=7.5}

glimpse(fs_nat <- hospitalizations("flusurv"))

ggplot(fs_nat, aes(wk_end, rate)) +
geom_line(aes(color=age_label, group=age_label)) +
facet_wrap(~sea_description, scales="free_x") +
scale_color_ipsum(name=NULL) +
labs(x=NULL, y="Rates per 100,000 population",
title="FluSurv-NET :: Entire Network :: All Seasons :: Cumulative Rate") +


glimpse(hospitalizations("eip", "Colorado"))


glimpse(hospitalizations("ihsp", "Oklahoma"))

### Retrieve ILINet Surveillance Data

```{r message=FALSE, warning=FALSE}
walk(c("national", "hhs", "census", "state"), ~{

ili_df <- ilinet(region = .x)


ggplot(ili_df, aes(week_start, unweighted_ili, group=region, color=region)) +
geom_line() +
viridis::scale_color_viridis(discrete=TRUE) +
labs(x=NULL, y="Unweighted ILI", title=ili_df$region_type[1]) +
theme_ipsum_rc(grid="XY") +
theme(legend.position = "none") -> gg



### Retrieve weekly state-level ILI indicators per-state for a given season

```{r message=FALSE, warning=FALSE, fig.width=10, fig.height=5}

xdf <- map_df(2008:2017, ili_weekly_activity_indicators)

count(xdf, weekend, ili_activity_label) %>%
complete(weekend, ili_activity_label) %>%
ggplot(aes(weekend, ili_activity_label, fill=n)) +
geom_tile(color="#c2c2c2", size=0.1) +
scale_x_date(expand=c(0,0)) +
viridis::scale_fill_viridis(name="# States", na.value="White") +
labs(x=NULL, y=NULL, title="Weekly ILI Indicators (all states)") +
coord_fixed(100/1) +
theme_ipsum_rc(grid="") +

### Pneumonia and Influenza Mortality Surveillance

```{r message=FALSE, warning=FALSE}
(nat_pi <- pi_mortality("national"))

select(nat_pi, wk_end, percent_pni, baseline, threshold) %>%
gather(measure, value, -wk_end) %>%
ggplot(aes(wk_end, value)) +
geom_line(aes(group=measure, color=measure)) +
scale_y_percent() +
scale_color_ipsum(name = NULL, labels=c("Baseline", "Percent P&I", "Threshold")) +
labs(x=NULL, y="% of all deaths due to P&I",
title="Percentage of all deaths due to pneumonia and influenza, National Summary") +
theme_ipsum_rc(grid="XY") +

(st_pi <- pi_mortality("state"))

(reg_pi <- pi_mortality("region"))

### Retrieve metadata about U.S. State CDC Provider Data

```{r message=FALSE, warning=FALSE}

### Retrieve WHO/NREVSS Surveillance Data

```{r message=FALSE, warning=FALSE}
glimpse(xdat <- who_nrevss("national"))

percent_positive = percent_positive / 100) %>%
ggplot(aes(wk_date, percent_positive)) +
geom_line() +
scale_y_percent(name="% Positive") +
labs(x=NULL, title="WHO/NREVSS Surveillance Data (National)") +




## Code of Conduct

Please note that this project is released with a [Contributor Code of Conduct]( By participating in this project you agree to abide by its terms.