Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sankey Diagram - Bed Movements

Repository for building example Sankey diagrams for bed reconfiguration.

The repository contains two related workflows:

  • 2 State: compare one snapshot state against another
  • 3 State: compare previous, current, and proposed states

Repository Structure

.
|-- data/
|   |-- ward_snapshots_current_proposed.xlsx
|   |-- moves_current_proposed.xlsx
|   |-- ward_snapshots_3_state.xlsx
|   |-- moves_3_state.xlsx
|   `-- processed/
|       |-- snapshot_summary.csv
|       |-- moves_summary.csv
|       `-- 3_state/
|           |-- snapshot_summary.csv
|           `-- moves_summary.csv
|-- outputs/
|-- R/
|   |-- 2 State/
|   |   |-- 01_process_beds.R
|   |   |-- 02_sankey.R
|   |   `-- 03_export_selfcontained.R
|   `-- 3 State/
|       |-- 01_process_beds.R
|       |-- 02_sankey.R
|       `-- 03_export_selfcontained.R
|-- lancs_ward_sankey_example.Rproj
`-- README.md

Workflow

Each state option follows the same three-step pattern:

  1. 01_process_beds.R Reads Excel input files from data/, standardises columns, and writes processed summaries to data/processed/.
  2. 02_sankey.R Reads the processed CSV files, applies filters and status settings, and writes the Sankey HTML output to outputs/.
  3. 03_export_selfcontained.R Re-runs the Sankey build and writes a self-contained HTML file for easier sharing.

How To Run

Open the project in RStudio, or set the working directory to the project root before sourcing scripts.

Run The 2-State Workflow

source(here::here("R", "2 State", "01_process_beds.R"))
source(here::here("R", "2 State", "02_sankey.R"))
source(here::here("R", "2 State", "03_export_selfcontained.R"))

Outputs:

  • outputs/sankey_diagram_bed_movements_2_state.html
  • outputs/sankey_diagram_bed_movements_2_state_selfcontained.html

Run The 3-State Workflow

source(here::here("R", "3 State", "01_process_beds.R"))
source(here::here("R", "3 State", "02_sankey.R"))
source(here::here("R", "3 State", "03_export_selfcontained.R"))

Outputs:

  • outputs/sankey_diagram_bed_movements_3_state.html
  • outputs/sankey_diagram_bed_movements_3_state_selfcontained.html

Input Files

2-State Inputs

These are defined near the top of R/2 State/01_process_beds.R:

snapshot_path <- here::here("data", "ward_snapshots_current_proposed.xlsx")
moves_path <- here::here("data", "moves_current_proposed.xlsx")

To use a different dataset, change those file names to the workbook you want to process.

3-State Inputs

These are defined near the top of R/3 State/01_process_beds.R:

snapshot_path <- here::here("data", "ward_snapshots_3_state.xlsx")
moves_path <- here::here("data", "moves_3_state.xlsx")

To switch to a different 3-state dataset, update these paths and rerun 01_process_beds.R.

Processed Files

The processing scripts write standardised CSV files that are then used by the Sankey scripts.

2-State Processed Files

output_dir <- here::here("data", "processed")

This creates:

  • data/processed/snapshot_summary.csv
  • data/processed/moves_summary.csv

3-State Processed Files

output_dir <- here::here("data", "processed", "3_state")

This creates:

  • data/processed/3_state/snapshot_summary.csv
  • data/processed/3_state/moves_summary.csv

If you change the raw input files, rerun the relevant 01_process_beds.R script before rerunning the Sankey export.

How To Change Sankey Parameters

The main parameters to edit are at the bottom of each 02_sankey.R script.

1. Change Which Statuses Are Compared

For 2-state, edit:

left_status <- "Current - January 2026"
right_status <- "Proposed"

For 3-state, edit:

previous_status <- "Previous - April 2025"
current_status <- "Current - January 2026"
proposed_status <- "Proposed"

These values must match the Status values in the snapshot input files.

2. Filter To A Specific Hospital

For 2-state, edit these variables in R/2 State/02_sankey.R:

start_hospitals <- c("RPH")
end_hospitals <- c("RPH")

Use NULL to remove the filter:

start_hospitals <- NULL
end_hospitals <- NULL

For 3-state, edit:

previous_hospitals <- c("RPH")
current_hospitals <- c("RPH")
proposed_hospitals <- c("RPH")

You can also use different hospitals for each state if required.

3. Filter To A Specific Division

For 2-state:

start_divisions <- c("MED")
end_divisions <- c("MED")

For 3-state:

previous_divisions <- c("MED")
current_divisions <- c("MED")
proposed_divisions <- c("MED")

Set these back to NULL to include all divisions.

4. Change The Processed Inputs Used By The Sankey Script

If you want the Sankey script to read from a different processed location, change the paths near the top of each 02_sankey.R.

Example from 2-state:

snapshot_path <- here::here("data", "processed", "snapshot_summary.csv")
moves_path <- here::here("data", "processed", "moves_summary.csv")

Example from 3-state:

snapshot_path <- here::here(
  "data",
  "processed",
  "3_state",
  "snapshot_summary.csv"
)

moves_path <- here::here(
  "data",
  "processed",
  "3_state",
  "moves_summary.csv"
)

In normal use, these do not need to change unless you want to maintain multiple processed datasets side by side.

5. Change The Output File Names

The export names are set at the bottom of each 02_sankey.R file and in each 03_export_selfcontained.R file.

Current outputs are:

  • sankey_diagram_bed_movements_2_state.html
  • sankey_diagram_bed_movements_2_state_selfcontained.html
  • sankey_diagram_bed_movements_3_state.html
  • sankey_diagram_bed_movements_3_state_selfcontained.html

Expected Input Columns

The processing scripts expect the snapshot workbooks to include columns such as:

  • Division
  • Hospital
  • Ward
  • Specialty / SBU
  • Bed Type
  • Beds
  • Status

The moves workbooks are expected to include origin and destination fields, including hospital, division, ward, specialty, bed type, and Beds.

For the 3-state moves file, a stage field is also expected and is mapped to move_stage.

Typical Change Scenarios

Compare A Single Hospital Only

  1. Update the relevant *_hospitals variables in 02_sankey.R.
  2. Leave all division filters as NULL unless you also want a division cut.
  3. Rerun 02_sankey.R and, if needed, 03_export_selfcontained.R.

Use A New Snapshot Workbook

  1. Update snapshot_path and moves_path in the relevant 01_process_beds.R.
  2. Run 01_process_beds.R.
  3. Check that the status values in the new data match the status names used in 02_sankey.R.
  4. Run 02_sankey.R.

Change From Whole-System To Division-Level Filtering

  1. Leave hospital filters as NULL.
  2. Set the division vectors in 02_sankey.R.
  3. Rerun the Sankey script.

Notes

  • The repository does not currently include a renv.lock file.
  • 03_export_selfcontained.R requires Pandoc. The script checks common installation paths and uses RSTUDIO_PANDOC if available.
  • The Sankey scripts stop with an error if a chosen status does not exist in the processed snapshot data.

Contributors

This repository has been created and developed by:

About

Repository for the creation of sankey diagrams to show bed movements

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages