An R package to access and visualize CDC measles case data.
The cdcmeasles package provides tools to:
- Download measles case data directly from official CDC JSON endpoints
- Access both weekly (recent) and yearly (historical) case counts
- Create time series plots, bar charts, and choropleth maps
- Check data availability and retrieve metadata
Install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("dwchal/cdcmeasles")library(cdcmeasles)
# Check if data is available
is_data_available(verbose = TRUE)
# Download weekly data (recent cases)
weekly <- get_measles_data("weekly")
head(weekly)
# Download yearly data (historical)
yearly <- get_measles_data("yearly")
head(yearly)
# Get a quick summary of current year
get_current_year_summary()The package includes several ggplot2-based visualization functions:
# Time series plot
weekly <- get_measles_data("weekly")
plot_measles_time_series(weekly, show_points = TRUE)
# Yearly bar chart
yearly <- get_measles_data("yearly")
plot_measles_bars(yearly, highlight_recent = TRUE)
# Historical time series
plot_measles_time_series(
yearly,
date_col = "year",
title = "Historical Measles Cases"
)For state-level data, create choropleth maps (requires maps package):
state_data <- data.frame(
state = c("california", "texas", "new york"),
cases = c(50, 30, 45)
)
plot_measles_state_map(state_data)The package accesses two official CDC data endpoints:
| Type | URL | Description |
|---|---|---|
| Weekly | https://www.cdc.gov/wcms/vizdata/measles/MeaslesCasesWeekly.json | Recent weekly case counts |
| Yearly | https://www.cdc.gov/wcms/vizdata/measles/MeaslesCasesYear.json | Historical annual data |
| Column | Type | Description |
|---|---|---|
week_start |
Date | Start of reporting week |
week_end |
Date | End of reporting week |
cases |
Integer | Number of reported cases |
| Column | Type | Description |
|---|---|---|
year |
Integer | Year of data |
cases |
Integer | Total cases for year |
states_with_cases |
Integer | States reporting cases |
outbreaks |
Character | Outbreak descriptions |
get_measles_data()- Download weekly or yearly datais_data_available()- Check CDC endpoint accessibilityget_measles_metadata()- Get dataset metadataget_cdc_urls()- View data endpoint URLsget_current_year_summary()- Quick summary of recent data
clean_measles_data()- Standardize and clean data
plot_measles_time_series()- Time series line plotplot_measles_bars()- Bar chart for yearly dataplot_measles_state_map()- US choropleth mapplot_measles_dashboard()- Combined dashboard view
Required:
- httr
- jsonlite
- ggplot2
- rlang
Optional:
- maps (for
plot_measles_state_map()) - patchwork (for
plot_measles_dashboard())
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
This package is not officially affiliated with or endorsed by the CDC. The data is provided by the CDC and made available through this package for ease of access and analysis.
The CDC occasionally updates their data structure and URLs. If you encounter issues:
- Check
is_data_available(verbose = TRUE)for connectivity - Verify URLs with
get_cdc_urls() - Visit the CDC measles page for updates
- Report issues at https://github.com/dwchal/cdcmeasles/issues