Michigan Covid Cases
michigan-covid-cases.Rmd
Background
I’ve been following COVID cases, deaths, and hospitalizations in Michigan & the US closely since the beginning of the pandemic. There’s lots of data to work with, which provides lots of opportunities for data analysis and visualization. This particular visualization is quite simple, and plots cases and deaths as a function of time. Whats unique about this plot is that it can show how deaths usually follow cases by 3 or so weeks.
The link for the data is scraped using Python, downloaded and cleaned/massaged in R, stored in the ds303pkg
package, and visualized in R’s Plotly interface
This data set contains cumulative cases, new cases, cumulative deaths, and new deaths for each county for each date in roughly the last two years. For my visualization, I simply want total cases and deaths in the state, so the data is grouped by date and deaths and cases are summed.
Initial Data Visualization:
plotly::plot_ly(
mi_covid,
x = ~Date,
y = ~Cases
)
With 7 day moving average and deaths:
mi_cases_by_day <- mi_covid %>%
dplyr::mutate(
cases_ma = zoo::rollapply(Cases, 7, mean, align = "center", fill = 0),
deaths_ma = zoo::rollapply(Deaths, 7, mean, align = "center", fill = 0)
)
ay <- list(overlaying = "y", side = "right", title = "Deaths")
plotly::plot_ly(mi_cases_by_day, x = ~Date) %>%
# Cases
plotly::add_trace(
y = ~Cases, alpha = .6, name = "Cases", type = "scatter",
color = I("coral1"), mode = "markers"
) %>%
# Cases MA
plotly::add_lines(
y = ~cases_ma, alpha = .8, name = "Cases MA", mode = "markers",
color = I("coral1")
) %>%
# Deaths
plotly::add_trace(
name = "Deaths", yaxis = "y2", alpha = .15, y = ~Deaths, x = ~Date,
color = I("darkorchid1"), type = "scatter", mode = "markers"
) %>%
# Deaths MA
plotly::add_lines(
name = "Deaths MA", yaxis = "y2", y = ~deaths_ma, x = ~Date,
color = I("darkorchid1"), alpha = .8 / 4, mode = "markers"
) %>%
plotly::layout(
title = "Michigan COVID Cases/Deaths<br>With 7-day Moving Average",
yaxis2 = ay, legend = list(bgcolor = "rgba(0,0,0,0)"),
margin = list(r = 50, t = 50)
) %>%
plotly::rangeslider()
Log 10 chart
ay <- list(overlaying = "y", side = "right", title = "Deaths")
plotly::plot_ly(mi_cases_by_day, x = ~Date) %>%
# Cases
plotly::add_trace(
y = ~ log10(Cases), alpha = .6, name = "Cases", type = "scatter",
color = I("coral1"), mode = "markers"
) %>%
# Cases MA
plotly::add_lines(
y = ~ log10(cases_ma), alpha = .8, name = "Cases MA", mode = "markers",
color = I("coral1")
) %>%
# Deaths
plotly::add_trace(
name = "Deaths", yaxis = "y2", alpha = .15, y = ~ log10(Deaths), x = ~Date,
color = I("darkorchid1"), type = "scatter", mode = "markers"
) %>%
# Deaths MA
plotly::add_lines(
name = "Deaths MA", yaxis = "y2", y = ~ log10(deaths_ma), x = ~Date,
color = I("darkorchid1"), alpha = .8 / 4, mode = "markers"
) %>%
plotly::layout(
title = "Michigan COVID Cases/Deaths<br>With 7-day Moving Average",
yaxis2 = ay, legend = list(bgcolor = "rgba(0,0,0,0)"),
margin = list(r = 50, t = 50)
) %>%
plotly::rangeslider()
Reflection
What ideas/suggestions from Claus Wilke’s helped shape your visualization?
Storytelling/comparison drove what I was after. Here, I’m trying to show how COVID deaths follow COVID cases, and choices made in this visualization are made to show that comparison.