COVID-19 data for the UK has been provided in an up to date and tidy form by Tom White and others. I’ve used this source to see how easy it is to plot this data on a map.
Plotting 🔗
This data set makes it very easy to plot case, test and death counts. We can grab it and put it into a data frame like so:
caseData <- read.csv("https://raw.githubusercontent.com/tomwhite/covid-19-uk-data/master/data/covid-19-cases-uk.csv") %>%
mutate(Date = as.Date(Date)) %>%
mutate(TotalCases = as.integer(TotalCases))
It looks like this:
Each row is a case measurement for a given area on a particular date. The AreaCode refers to an administrative region in the UK (more on this below). The data is in a similar format for death and test counts.
In order to get a snapshot of the most recent counts across all areas we can group by AreaCode and take a “slice”:
latestData <- caseData %>% group_by(AreaCode) %>% slice(which.max(Date))
It’s then a simple matter to plot, for example, the top 10 areas by case count:
top10 <- latestData %>% ungroup() %>% top_n(10, TotalCases)
which looks like this:
Mapping 🔗
Mapping this data is more problematic. The data includes an AreaCode that uniquely identifies a reporting area. However, there’s no simple way to turn these codes into coordinates (or boundaries for that matter) that I could find.
In England and Northern Ireland the AreaCode is a local authority code and the data is readily available from the ONS Geoportal. For Wales, the code represents a Primary Care Trust code and I was able to extract the coordinates somewhat roughly from postcode data found in Open Data Camden.
Alas for Scotland, where the code represents a “Health Board Area”, I was not able to find coordinates.
Anyway, using the data I could find it was then possible to plot a Leaflet map:
For full details of the R code and an explorable map please see this blog post.