This file contains code used to create Figures 1, 2, and 3 and some values for Table 1. We also print out useful underlying data for the plots
Raw code can be downloaded by selecting the Download Rmd option from the Code drop down menu at the top of this page.
R packages and helper functions….
library(tidyverse)
library(curl)
library(readxl)
library(forcats)
library(ggthemes)
library(socviz)
library(here)
#Helper function
`%nin%` <- negate(`%in%`)
#Short cut for csv output with html tables
my_datatable <- function(x){
DT::datatable(x, extensions = "Buttons", options = list(dom = "Bfrtip",
buttons = c("csv")))
}
#Baseline plot settings
theme_set(theme_minimal(base_family = "Roboto", base_size = 20) +
theme(panel.grid.minor = element_blank(),
axis.title.y = element_text(margin = margin(0, 20, 0, 0)),
axis.title.x = element_text(margin = margin(20, 0, 0, 0)),
plot.caption = element_text(colour = "#AAAAAA"),
plot.margin = margin(3,15,3,3,"mm")))
#global options for scientific numbers and significant digits.
options(scipen = 10,
digits = 1)Figure 1 shows the distribution of care home size across the 4 nations with violin and boxplots.
The data used to create this plot is derived from information from the relevant Care inspectorates in each nation. These files required some pre-processing which can be found in on this page. The derived, combined, dataset is imaginatively called uk and is found in the derived_data folder as a feather object on the project GitHub pages.
#read in wrangled data to global environment
uk <- feather::read_feather(here("derived_data/uk.feather"))This plot shows the distribution of all adult care homes in each country, not care homes for older people.
uk %>%
ggplot(aes(fct_rev(country), `Care homes beds`, colour = country)) +
geom_violin(alpha = 0.5) +
geom_boxplot(width = 0.2) +
scale_colour_wsj() +
theme(legend.position = "none",
plot.caption = element_text(size = 12)) +
coord_flip() +
labs(title = "Distribution of care home size",
subtitle = "(care homes for all adults)",
x = "",
y = "Number of care home beds",
caption = "Outer line indicates distribution\nStrong vertical line in box indicates the median\nBox limits indicate 25th and 75th percentile\nDots indicate statistical outliers\nSources: Care Quality Commission England, Care Inspectorate Scotland,\n Regulation and Quality Improvement Authority Northern Ireland, and the Care Inspectorate Wales\nCode:https://github.com/davidhen/ltc_covid_uk") -> fig_1
fig_1This plot shows the distribution when filtering for older people’s care homes only. We can’t include Wales in this plot as we can’t filter between care home types. See the table below for more info.
uk %>%
filter(country != "Wales") %>%
filter(case_when(
country == "England" ~ `Service user band - Older People` == "Y",
country == "Scotland" ~ Subtype %in% c("Older People", "Respite Care and Short Breaks"),
country == "Northern Ireland" ~ str_detect(`Categories of Care`, "I") |
str_detect(`Categories of Care`, "DE")
)) %>%
ggplot(aes(fct_rev(country), `Care homes beds`, colour = country)) +
geom_violin(alpha = 0.5) +
geom_boxplot(width = 0.2) +
scale_colour_wsj() +
theme(legend.position = "none",
plot.caption = element_text(size = 12)) +
coord_flip() +
labs(title = "Distribution of care home size",
subtitle = "(care homes for older adults)",
x = "",
y = "Number of care home beds",
caption = "Outer line indicates distribution\nStrong vertical line in box indicates the median\nBox limits indicate 25th and 75th percentile\nDots indicate statistical outliers\nSources: Care Quality Commission England, Care Inspectorate Scotland,\n Regulation and Quality Improvement Authority Northern Ireland, and the Care Inspectorate Wales\nCode:https://github.com/davidhen/ltc_covid_uk") -> fig_1a
fig_1aSome useful summary figures which contribute to Table 1 in the report
This uses all data in the uk data object
uk %>%
group_by(country) %>%
summarise(total_number_of_homes = n(),
total_number_of_beds = sum(`Care homes beds`, na.rm = TRUE)) %>%
mutate(total_number_of_beds = as.numeric(total_number_of_beds)) %>%
bind_rows(summarise_all(., funs(if(is.numeric(.)) sum(.) else "Total"))) %>%
my_datatable(.)Note 15 care homes in Scotland do not provide total_beds figures.
Care Inspectorate for Wales does not classify care home type by older people so we must remove them from this summary. The code block below shows how we filtered the other nations data to include only care homes for older people. This is subjective and there is no clear documentation or metadata to aid with this. It is also important to note that some care homes may include a mix of older and younger clients.
uk %>%
filter(country != "Wales") %>%
filter(case_when(
country == "England" ~ `Service user band - Older People` == "Y",
country == "Scotland" ~ Subtype %in% c("Older People", "Respite Care and Short Breaks"),
country == "Northern Ireland" ~ str_detect(`Categories of Care`, "I") |
str_detect(`Categories of Care`, "DE")
)) %>%
group_by(country) %>%
summarise(total_number_of_homes = n(),
total_number_of_beds = sum(`Care homes beds`, na.rm = TRUE)) %>%
my_datatable(.)Note 10 care homes in Scotland do not provide total_beds figures.
Data for Figures 2 & 3 is sourced from the ONS Deaths registered in England and Wales available here
To calculate per 100,000 estimates we used population estimates from here and crudely added them in manually in the code as seen below.
#Assign url for ONS data and download into a temporary file
url <- "https://www.ons.gov.uk/file?uri=%2fpeoplepopulationandcommunity%2fbirthsdeathsandmarriages%2fdeaths%2fdatasets%2fweeklyprovisionalfiguresondeathsregisteredinenglandandwales%2f2020/publishedweek282020.xlsx"
temp <- tempfile()
temp <- curl_download(url=url, destfile=temp, quiet=FALSE)
#Extract weekly data for each country from "UK" Worksheet and tidy up
uk_deaths_data <-
read_xlsx(temp, sheet="UK - Covid-19 - Weekly reg",
range = "A4:AB12") %>%
slice(5:8) %>%
select(-`Week number`) %>%
rename(country = `...2`) %>%
#reshape to long format
pivot_longer(`1`:`26`, names_to = "week_number",
values_to = "covid_deaths") %>%
#coerce week number to integer
mutate(week_number = as.integer(week_number)) %>%
#drop rows before week 11
filter(week_number >= 11) %>%
#coerce country variable to a factor
mutate(country = factor(country,
levels = c("England", "Scotland",
"Wales", "Northern Ireland")),
#manually add in population size
pop = case_when(
country == "England" ~ 56286961,
country == "Wales" ~ 3152879,
country == "Scotland" ~ 5463300,
country == "Northern Ireland" ~ 1893667),
#Calculate deaths per 100,000
deaths_100000 = covid_deaths/pop * 100000)
#Print out the result
uk_deaths_data %>%
round_df() %>%
my_datatable(.)Using the uk_deaths_data object we can summarise and plot out the number of deaths in the whole UK in each week.
uk_deaths_data %>%
#summarise the uk deaths data table
group_by(week_number) %>%
summarise(tot_deaths = sum(covid_deaths)) %>%
#and pipe into the plot
ggplot(aes(week_number, tot_deaths)) +
geom_line(colour = wsj_pal()(1)) +
scale_x_continuous(breaks = scales::pretty_breaks(n = 12)) +
scale_y_continuous(breaks = scales::pretty_breaks(),
limits = c(0, 10000)) +
labs(title = "Weekly deaths attributed to COVID-19 in the UK",
x = "Week number",
y = "",
caption = "Source:ONS Deaths registered in England and Wales, UK deaths\nCode:https://github.com/davidhen/ltc_covid_uk") -> fig_2
fig_2Same data as before but plotting per 100k figures now as opposed to absolute numbers.
uk_deaths_data %>%
ggplot(aes(week_number, deaths_100000, colour = country)) +
geom_line(size = 1.2) +
scale_colour_wsj() +
scale_x_continuous(breaks = scales::pretty_breaks(n = 12)) +
scale_y_continuous(breaks = scales::pretty_breaks()) +
theme(legend.position = "top") +
labs(title = "Weekly deaths attributed to COVID-19 per 100,000",
subtitle = "by UK nation",
x = "Week number",
y = "",
colour = "",
caption = "Source:ONS Deaths registered in England and Wales, UK deaths\nCode:https://github.com/davidhen/ltc_covid_uk") -> fig_3
fig_3A figure referenced in the text of the report - total COVID-19 deaths Weeks 11-26
uk_deaths_data %>%
summarise(total_deaths = sum(covid_deaths)) Useful summary figures
uk_deaths_data %>%
group_by(country) %>%
summarise(covid_deaths = sum(covid_deaths),
pop = pop) %>%
distinct() %>%
mutate(total_per_100k = covid_deaths/pop * 100000) %>%
round_df() %>%
my_datatable(.)More useful summary figures
uk_deaths_data %>%
group_by(country) %>%
summarise(covid_deaths = sum(covid_deaths),
pop = pop) %>%
distinct() %>%
ungroup() %>%
summarise(covid_deaths = sum(covid_deaths),
uk_pop = sum(pop)) %>%
mutate(total_uk_deaths_100k = covid_deaths/uk_pop * 100000)devtools::session_info()## ─ Session info ────────────────────────────────────────
## setting value
## version R version 4.1.0 (2021-05-18)
## os macOS Big Sur 11.4
## system aarch64, darwin20
## ui RStudio
## language (EN)
## collate en_GB.UTF-8
## ctype en_GB.UTF-8
## tz Europe/London
## date 2021-06-14
##
## ─ Packages ────────────────────────────────────────────
## package * version date lib source
## assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0)
## backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.0)
## broom 0.7.7 2021-06-13 [1] CRAN (R 4.1.0)
## bslib 0.2.5.1 2021-05-18 [1] CRAN (R 4.1.0)
## cachem 1.0.5 2021-05-15 [1] CRAN (R 4.1.0)
## callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0)
## cellranger 1.1.0 2016-07-27 [1] CRAN (R 4.1.0)
## cli 2.5.0 2021-04-26 [1] CRAN (R 4.1.0)
## colorspace 2.0-1 2021-05-04 [1] CRAN (R 4.1.0)
## crayon 1.4.1 2021-02-08 [1] CRAN (R 4.1.0)
## crosstalk 1.1.1 2021-01-12 [1] CRAN (R 4.1.0)
## curl * 4.3.1 2021-04-30 [1] CRAN (R 4.1.0)
## DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0)
## dbplyr 2.1.1 2021-04-06 [1] CRAN (R 4.1.0)
## desc 1.3.0 2021-03-05 [1] CRAN (R 4.1.0)
## devtools 2.4.2 2021-06-07 [1] CRAN (R 4.1.0)
## digest 0.6.27 2020-10-24 [1] CRAN (R 4.1.0)
## dplyr * 1.0.6 2021-05-05 [1] CRAN (R 4.1.0)
## DT 0.18 2021-04-14 [1] CRAN (R 4.1.0)
## ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0)
## evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0)
## fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0)
## farver 2.1.0 2021-02-28 [1] CRAN (R 4.1.0)
## fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0)
## feather 0.3.5 2019-09-15 [1] CRAN (R 4.1.0)
## forcats * 0.5.1 2021-01-27 [1] CRAN (R 4.1.0)
## fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0)
## generics 0.1.0 2020-10-31 [1] CRAN (R 4.1.0)
## ggplot2 * 3.3.3 2020-12-30 [1] CRAN (R 4.1.0)
## ggthemes * 4.2.4 2021-01-20 [1] CRAN (R 4.1.0)
## glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0)
## gtable 0.3.0 2019-03-25 [1] CRAN (R 4.1.0)
## haven 2.4.1 2021-04-23 [1] CRAN (R 4.1.0)
## here * 1.0.1 2020-12-13 [1] CRAN (R 4.1.0)
## highr 0.9 2021-04-16 [1] CRAN (R 4.1.0)
## hms 1.1.0 2021-05-17 [1] CRAN (R 4.1.0)
## htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 4.1.0)
## htmlwidgets 1.5.3 2020-12-10 [1] CRAN (R 4.1.0)
## httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.0)
## jquerylib 0.1.4 2021-04-26 [1] CRAN (R 4.1.0)
## jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0)
## knitr 1.33 2021-04-24 [1] CRAN (R 4.1.0)
## labeling 0.4.2 2020-10-20 [1] CRAN (R 4.1.0)
## lifecycle 1.0.0 2021-02-15 [1] CRAN (R 4.1.0)
## lubridate * 1.7.10 2021-02-26 [1] CRAN (R 4.1.0)
## magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0)
## memoise 2.0.0 2021-01-26 [1] CRAN (R 4.1.0)
## modelr 0.1.8 2020-05-19 [1] CRAN (R 4.1.0)
## munsell 0.5.0 2018-06-12 [1] CRAN (R 4.1.0)
## patchwork * 1.1.1 2020-12-17 [1] CRAN (R 4.1.0)
## pillar 1.6.1 2021-05-16 [1] CRAN (R 4.1.0)
## pkgbuild 1.2.0 2020-12-15 [1] CRAN (R 4.1.0)
## pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0)
## pkgload 1.2.1 2021-04-06 [1] CRAN (R 4.1.0)
## prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0)
## processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0)
## ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0)
## purrr * 0.3.4 2020-04-17 [1] CRAN (R 4.1.0)
## R6 2.5.0 2020-10-28 [1] CRAN (R 4.1.0)
## Rcpp 1.0.6 2021-01-15 [1] CRAN (R 4.1.0)
## readr * 1.4.0 2020-10-05 [1] CRAN (R 4.1.0)
## readxl * 1.3.1 2019-03-13 [1] CRAN (R 4.1.0)
## rematch 1.0.1 2016-04-21 [1] CRAN (R 4.1.0)
## remotes 2.4.0 2021-06-02 [1] CRAN (R 4.1.0)
## reprex 2.0.0 2021-04-02 [1] CRAN (R 4.1.0)
## rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.0)
## rmarkdown * 2.8 2021-05-07 [1] CRAN (R 4.1.0)
## rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0)
## rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0)
## rvest 1.0.0 2021-03-09 [1] CRAN (R 4.1.0)
## sass 0.4.0 2021-05-12 [1] CRAN (R 4.1.0)
## scales 1.1.1 2020-05-11 [1] CRAN (R 4.1.0)
## sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0)
## socviz * 1.2 2020-06-10 [1] CRAN (R 4.1.0)
## stringi 1.6.2 2021-05-17 [1] CRAN (R 4.1.0)
## stringr * 1.4.0 2019-02-10 [1] CRAN (R 4.1.0)
## testthat 3.0.2 2021-02-14 [1] CRAN (R 4.1.0)
## tibble * 3.1.2 2021-05-16 [1] CRAN (R 4.1.0)
## tidyr * 1.1.3 2021-03-03 [1] CRAN (R 4.1.0)
## tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0)
## tidyverse * 1.3.1 2021-04-15 [1] CRAN (R 4.1.0)
## usethis 2.0.1 2021-02-10 [1] CRAN (R 4.1.0)
## utf8 1.2.1 2021-03-12 [1] CRAN (R 4.1.0)
## vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0)
## withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.0)
## xfun 0.23 2021-05-15 [1] CRAN (R 4.1.0)
## xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.0)
## yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0)
##
## [1] /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library