# Statistics for the COVID-19 outbreak in Sweden

This page provides plots and visualisations of currently available statistics for the novel coronavirus (COVID-19) outbreak in Sweden.

This page is largely the result of a personal exercise in data analysis but since it received some interest on Twitter, I have set this page to automatically update every day following the daily updates of the national statistics from Sweden's Public Health Authority (Folkhälsomyndigheten).

The data presented here is scraped from a publicly available source (c19.se), and I am not responsible for the accuracy of these numbers. The code used to produce the images on this page is provided below if you would like to reproduce these or see how it is done.

Please note: occasionally c19.se subtly changes their webpage which breaks my code and may cause this page not to be updated correctly, or at all. Since I don't actively check/maintain this page, I might not notice. If this happens feel free to leave a comment below so I will notice, and I can try to fix the problem. Sorry in advance for any disappointment...

## Total confirmed cases and deaths in Sweden

Summary of confirmed cases and deaths in Sweden per day, showing the current 7-day moving average.

## Regional trends

The below charts show the change in cases and deaths by county over the last 7 days relative to the previous 7-day period. This means that a value over zero means the number new cases/deaths may be increasing with time, and under zero means they may be decreasing. Infinite values are removed.

## Code

Below is the code, written in R, used to scrape the data from the web and produce the above images. This might be of interest to those with an interest in data science or analysis as it contains examples of web scraping, all manner of data wrangling with tidyverse, simple calculations, plotting with ggplot, choropleth maps, and so on.

The geoJSON shapefile used to produce the choropleth maps was downloaded from here and re-hosted at this site for convenience.

The code here is essentially the same as run on this website's server to generate the images on the page here; the only difference is the data frame map_tidy is pre-exported as a text file so it is not created from the geoJSON file every time. Cron then runs the script and re-builds the page every day.