knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(WrangleMACovidData)
# weekly_dashboard_file <- system.file("extdata", "Weekly-Dashboard-data-08122020.xlsx", package = "WrangleMACovidData")

1) Download the latest weekly public health report spreadsheet of raw data from the Massachusetts government website.

2) Run the macovid_read_weekly_for_map() function on the downloaded spreadsheet, such as

ma_covid_data <- macovid_read_weekly_for_map("Weekly-Dashboard-data.xlsx")

3) Run the generate_mass_covid_map_by_place() function on the resulting sf object. That function has 4 arguments: the_ma_covid_data, the_fill_palette, the_labels, and the_outline_color (which defaults to "white").

the_ma_covid_data should be the sf object you generated above. the_fill_palette needs to be a palette created by leaflet::colorFactor(). This package has two built-in color vectors for your use if desired: positivity_colors and case_colors.

Here's example code to generate a map of test positivity in the last 14 days:

positivity_labels <- glue::glue("<strong>{ma_covid_data$Place}</strong><br/>Positivity: {ma_covid_data$PositivityRate}%<br />Avg daily cases per 100K: {ma_covid_data$DailyAvgCases}") %>% 
  lapply(htmltools::HTML)


positivity_palette <- leaflet::colorFactor(positivity_colors, levels = c("1.0 or Below", "Very Low", "Low", "Moderate", "Concern", "High", "Very High"), ordered = TRUE)

positivity_fill_color <- ~positivity_palette(ma_covid_data$PositivityCategory)

positivity_map <- generate_mass_covid_map_by_place(ma_covid_data, positivity_fill_color, positivity_labels)

And here is one for daily average cases per 100K in the last 14 days, attempting to mimic the DPH color scheme for mapping daily average cases by community in the past 14 days:

case_labels <- glue::glue("<strong>{ma_covid_data$Place}</strong><br/>Avg daily cases per 100K: {ma_covid_data$DailyAvgCases}<br />Positivity: {ma_covid_data$PositivityRate}%") %>% 
  lapply(htmltools::HTML)


case_palette <- leaflet::colorFactor(case_colors, levels = c("White", "Green", "Yellow", "Red"), ordered = TRUE)

case_fill_color <- ~case_palette(ma_covid_data$CaseCategory)

case_map <- generate_mass_covid_map_by_place(ma_covid_data, case_fill_color, case_labels, the_outline_color = "black")


smach/WrangleMACovidData documentation built on Jan. 25, 2021, 9:08 a.m.