Visualising Features of A&E Waiting Time Data Using Run Charts

In analytics, run charts are used to identify and display trends in data over time. In this post we show how to use the AnalytiXagility platform to plot a basic run chart to visualise features of A&E attendance data over time.

Output

This exemplar describes how to produce the following plot:

Related Blog Posts

This post is one of a series that is intended to be read in sequence. The following posts provide a full description of:

Data Source

The data we have used in this article has been sourced from NHS England: Weekly A&E SitReps 2013-14. This data has been cleaned up, converted to a CSV file, and then loaded into the AnalytiXagility platform. You can ask for a copy to be made available to your workspace. The data is called ae_england_20140105 in the AnalytiXagility workspace.

Learning Outcomes

In this post we:

Demonstrate techniques used in the construction of a layered plot, including formatting labels and annotating the plot using ggplot2.

Explore the manipulation and consideration of date data using scales.
Workflow

Step 1 – Set up environment

Load the relevant libraries:

library(ggplot2)
library(scales)

Import the data into R console workspace:

ae_data <- xap.read_table("ae_england_20140105")

Use the head() function to have a quick look at a section of the imported data:

head(ae_data)

The imported dataset ae_data includes percentage values of A&E attendees seen within 4 hours. The target, as set by NHS England, dictates that 95% of attendees are seen within this time. Let’s look first at fluctuations around the target over time; to do this, we first use the class() function to examine data types of ae_data$period and ae_data$percentagein4hoursorless_type1.:

class(ae_data$period)

class(ae_data$percentagein4hoursorless_type1)

## [1] "POSIXct" "POSIXt"

## [1] "numeric"

This tells us that ae_data$period is a POSIXdtPOSIXdt, which is an S3 class for datetime representation.

To select a specific time period, use the format function to extract the year from run_date and create an index. We will look at A&E attendances in 2012 and 2013 so we apply the derived index to re-evaluate run_date and run_metric:

Step 3 – Ready, set, plot!

In the recent blog post The Fundamentals of ggplot Explained, we introduced the basic concepts of ggplot2 and layering. We can start constructing our plot by creating a ggplot()object with labels and setting the colour scheme:

In plot d there are overlapping x-axis labels. To remedy this, use theme() to rotate text labels. In this case we have chosen 90 degrees:

e <- d + theme(axis.text.x = element_text(angle = 90, hjust = 1))
e

Step 4 – Annotate plot

We can add text to a plot using a geom_text() layer, so let’s append the statistic values derived in Step 2 to plot e. Each text group must have defined x and y co-ordinates, and we can use the data to identify these.

Step 5 – Tracing changes

Run charts are used extensively in analytics to track results from an implemented change. Let’s annotate our plot to reflect an implemented change and discuss the results. We first look at a single date, and then change over a period of time. To set a date to highlight on our plot and the text to label this, use: