---
title: "Emergency Care Waiting Times"
output:
flexdashboard::flex_dashboard:
orientation: rows
theme: cosmo
source_code: embed
logo: "E:/ED Occupancy Forecasting/HIB Dashboard/data/iad_logo_transparent_bw2.png"
navbar:
- { title: "About Hospital Information Branch", href: "https://www.health-ni.gov.uk/topics/doh-statistics-and-research", align: right }
---
```{r setup, message=F}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
#LOAD PACKAGES
library(flexdashboard)
library(knitr)
library(crosstalk)
library(DT)
library(tidyverse)
library(lubridate)
library(plotly)
library(haven)
library(scales)
library(stringr)
library(summarywidget)
color_from_middle <- function(data, color1,color2)
{
max_val = max(abs(data))
JS(sprintf("isNaN(parseFloat(value)) || value < 0 ? 'linear-gradient(90deg, transparent, transparent ' + (50 + value/%s * 50) + '%%, %s ' + (50 + value/%s * 50) + '%%,%s 50%%,transparent 50%%)': 'linear-gradient(90deg, transparent, transparent 50%%, %s 50%%, %s ' + (50 + value/%s * 50) + '%%, transparent ' + (50 + value/%s * 50) + '%%)'",
max_val,color2,max_val,color2,color1,color1,max_val,max_val))
}
# READ IN THE SAS FILE
ecwt <- read_sas("E:/Output/ec1_2008todate.sas7bdat")
# CREATE DATES / FACTORS
ecwt$HSC_Trust <- factor(ecwt$HSC_Trust)
ecwt$Department <- factor(ecwt$Department)
ecwt <- rename(ecwt, Date = Date_Mon_Year)
# CREATE A FINANCIAL YEAR IN THE FORMAT 2017/18 (with thanks to Nicole and Brian)
ecwt$Year <- ifelse(month(ecwt$Date) <= 3,
paste(as.character(year(ecwt$Date) - 1), str_sub(as.character(year(ecwt$Date)),3,4), sep = "/"),
paste(as.character(year(ecwt$Date)), str_sub(as.character(year(ecwt$Date) + 1),3,4), sep = "/"))
# CODE DEPARTMENT TYPE
Type1 <- c("Mater", "RVH", "RBHSC", "Belfast City", "Antrim Area", "Causeway", "Ulster",
"Craigavon Area", "Daisy Hill", "Altnagelvin Area", "South West Acute")
Type2 <- c("RVH-RAES", "Lagan Valley", "Downe")
Type3 <- c("Whiteabbey", "Mid-Ulster", "Ards MIU", "Bangor MIU", "South Tyrone",
"Armagh Community", "Tyrone County", "Brooklands")
# RECODE HSC TRUST, DEPARTMENT & TYPE
ecwt <-
ecwt %>%
mutate(Trust = recode_factor(HSC_Trust, '1' = 'Belfast', '2' = 'Northern', '3' = 'South Eastern',
'4' = "Southern", '5' = 'Western'),
Dept = recode_factor(Department, '1' = 'Mater', '2' = 'RVH', '3' = 'RVH-RAES', '4' = 'RBHSC',
'5' = 'Antrim Area', '6' = 'Causeway', '7' = 'Mid-Ulster',
'8' = 'Whiteabbey', '9' = 'Ards MIU', '10' = 'Bangor MIU',
'11' = 'Downe', '12' = 'Lagan Valley', '13' = 'Ulster',
'14' = 'Armagh Community', '15' = 'Craigavon Area',
'16' = 'Daisy Hill', '17' = 'South Tyrone', '18' = 'Altnagelvin Area',
'19' = 'South West Acute', '20' = 'Tyrone County',
'21' = 'Belfast City', '22' = 'Brooklands'),
Type = case_when(Dept %in% Type1 ~ "Type 1",
Dept %in% Type2 ~ "Type 2",
Dept %in% Type3 ~ "Type 3"))
# CREATE ORDERED FACTOR FOR EACH MONTH
ecwt$Month <- format(ecwt$Date, format = "%b %Y")
ecwt$Month <- factor(ecwt$Month, unique(ecwt$Month), ordered = TRUE)
# CREATE FINAL DATAFRAME & REMOVE INCORRECT DATA OF 78 TOTAL ATTENDANCES FOR BELFAST CITY (ED WAS CLOSED)
dat <-
ecwt %>%
mutate(PercentUnder4hrs = round(Within4Hrs / Total_Attend, 3)) %>%
select(Date, Month, Year, Trust, Dept, Type, Within4Hrs:Total_Attend, PercentUnder4hrs) %>%
mutate_at(vars(contains("Hrs")), funs(replace(., is.na(.), 0))) %>%
rename("Over12hrs" = Over12Hrs, "TotalAttendances" = Total_Attend, "Under4hrs" = Within4Hrs,
"Between4to12hrs" = `Between4-12Hrs`) %>%
filter(Under4hrs != 22 & TotalAttendances != 78) %>%
arrange(desc(Date))
# CREATE A COPY OF dat FOR GRAPHING THAT DOESN'T USE big.mark ","
dat_graph <- dat
dat[names(dat[7:10])] <- sapply(dat[names(dat[7:10])], format, big.mark = ",")
# CROSSTALK
shared_dat <- SharedData$new(dat)
sd_df <- SharedData$new(dat, group = shared_dat$groupName())
# CREATE DATAFRAMES TO USE WITH PLOTLY
tidy_dat <-
dat_graph %>%
gather(Category, Number, Under4hrs:PercentUnder4hrs)
tidy_dat$Category <- factor(
tidy_dat$Category,
ordered = TRUE,
levels = c(
"Under4hrs",
"Between4to12hrs",
"Over12hrs",
"TotalAttendances",
"PercentUnder4hrs"
)
)
# CREATE DATAFRAMES FOR TYPE 1 CHARTS
under4hrs_df <-
tidy_dat %>%
filter(Type == "Type 1" &
Category == "PercentUnder4hrs") %>%
select(Date, Month, Dept, Number) %>%
spread(Dept, Number)
#%>%
# mutate_at(vars(Mater:`Belfast City`), funs(. / 100))
over12hrs_df <-
tidy_dat %>%
filter(Type == "Type 1" &
Category == "Over12hrs") %>%
select(Date, Month, Dept, Number) %>%
spread(Dept, Number)
totalattend_df_type1 <-
tidy_dat %>%
filter(Type == "Type 1" &
Category == "TotalAttendances") %>%
select(Date, Month, Dept, Number) %>%
spread(Dept, Number)
type1_totals <-
dat_graph %>%
filter(Type == "Type 1") %>%
group_by(Month) %>%
select(Month, Under4hrs, Over12hrs, TotalAttendances) %>%
summarise(
Under4 = sum(Under4hrs),
Over12 = sum(Over12hrs),
Total = sum(TotalAttendances)
) %>%
mutate(Percentunder4 = round(Under4 / Total, 3)) %>%
select(-Under4)
type1_totals$target <- 0.95
# CREATE DATAFRAMES FOR TYPES 2, 3 & ALL TYPES
type2_totals <-
dat_graph %>%
filter(Type == "Type 2") %>%
group_by(Month) %>%
select(Month, Under4hrs, Over12hrs, TotalAttendances) %>%
summarise(
Under4 = sum(Under4hrs),
Over12 = sum(Over12hrs),
Total = sum(TotalAttendances)
) %>%
mutate(Percentunder4 = round(Under4 / Total, 3)) %>%
select(-Under4)
type3_totals <-
dat_graph %>%
filter(Type == "Type 3") %>%
group_by(Month) %>%
select(Month, Under4hrs, Over12hrs, TotalAttendances) %>%
summarise(
Under4 = sum(Under4hrs),
Over12 = sum(Over12hrs),
Total = sum(TotalAttendances)
) %>%
mutate(Percentunder4 = round(Under4 / Total, 3)) %>%
select(-Under4)
# All attendances not just Type 1
totalattend_df <-
dat_graph %>%
group_by(Month) %>%
summarise(Total = sum(TotalAttendances))
# Totals by HSC Trust
NI_totals <-
dat_graph %>%
mutate_at(vars(c('Trust')),
funs(as.character(.))) %>%
bind_rows(mutate(., Trust = 'Northern Ireland')) %>%
group_by(Date, Month, Year, Trust) %>%
summarise(Under4hrs = sum(Under4hrs),
TotalAttendances = sum(TotalAttendances)) %>%
ungroup() %>%
mutate(Trust = fct_relevel(Trust, 'Northern Ireland', after = Inf)) %>%
arrange(Month, Trust)
```
Table {data-icon="fa-table"}
===========================================================
Inputs {.sidebar}
-------------------------------------
```{r filter options}
filter_select("Dept", "Emergency Department:", sd_df, ~Dept)
filter_select("Value", "Year", sd_df, ~Year)
filter_checkbox("Trust", "HSC Trust:", sd_df, ~Trust)
filter_checkbox("Type", "ED Type", sd_df, ~Type)
filter_slider("Value", "Percent Waiting Under 4hrs:", sd_df, ~PercentUnder4hrs)
```
***
**Note: PDF option should be used for small reports only**
Row {data-height=750}
-------------------------------------------
###**EMERGENCY CARE WAITING TIMES (`r min(sd_df$origData()$Month)` - `r max(sd_df$origData()$Month)`)**
```{r datatable}
datatable(sd_df,
colnames = c("Date", "Month", "Year", "Trust", "Dept", "Type", "Under 4 Hours",
"Between 4 - 12 Hours", "Over 12 Hours", "Total", "Percent Under 4 Hours"),
extensions = c('Scroller','Buttons'),
plugins = 'natural',
rownames = F,
options = list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#2780E3', 'color': '#fff'});",
"}"),
scrollY = 300,
scroller = T,
dom = 'Bfrtip',
buttons = c('colvis', 'copy', 'csv', 'excel', 'pdf', 'print'),
columnDefs = list(list(className = 'dt-center', type = 'natural',
orderData = 0, targets = 1),
list(visible = FALSE, targets = 0))),
fillContainer = T,
class = 'cell-border stripe') %>%
formatStyle("PercentUnder4hrs",
background = color_from_middle(sd_df$data()$PercentUnder4hrs, 'lightblue', 'lightblue'),
backgroundSize = '95% 50%',
backgroundRepeat = 'no-repeat',
backgroundPosition = 'center') %>%
formatStyle('Month', 'text-align' = 'left') %>%
formatStyle(7:10, 'text-align' = 'right') %>%
formatPercentage(11, 1)
```
Row {data-height=250}
-----------------------------
### Value Box 1
```{r value box 1}
last_month <- format(max(NI_totals$Date), format = "%B %Y")
last_month_2 <- paste("Total attendances in", last_month)
last_amount <- NI_totals[[length(NI_totals$Date), "TotalAttendances"]]
valueBox(format(last_amount, big.mark = ","),
caption = last_month_2,
icon = "fa-hospital-alt",
href = "#all-types")
```
### Value Box 2
```{r value box 2}
last_year_month <- format(max(NI_totals$Date) - dyears(x = 1), format = "%B %Y")
last_year_amount <-
NI_totals %>%
filter(Trust == "Northern Ireland" & Date == max(Date) - dyears(x = 1)) %>%
pull(TotalAttendances)
attendance_change <- last_amount - last_year_amount
valueBox(format(attendance_change, big.mark = ","),
caption = paste(if_else(attendance_change > 0,
"Increase", "Decrease"),
"in attendances from the same month last year"),
icon = "fa-calendar-alt",
color = if_else(attendance_change > 0, "warning", "success"),
href = "#all-types")
```
### Value Box 3
```{r value box 3}
highest_amount <-
NI_totals %>%
filter(Trust == "Northern Ireland") %>%
tail(12) %>%
top_n(1, TotalAttendances) %>%
pull()
highest_month <-
format(NI_totals %>%
filter(Trust == "Northern Ireland") %>%
tail(12) %>%
top_n(1, TotalAttendances) %>%
pull(Month), format = "%B %Y")
highest_month <- paste("Higest attendances during the last year occurred in", highest_month)
valueBox(format(highest_amount, big.mark = ","),
caption = highest_month,
icon = "fa-arrow-alt-circle-up",
color = "danger",
href = "#all-types")
```
### Value Box 4
```{r value box 4}
four_hour_percent <-
dat_graph %>%
filter(Date == max(Date) & Type == "Type 1") %>%
summarise(four_total = sum(Under4hrs),
total = sum(TotalAttendances),
four_hour_percent = round(four_total / total, 2)) %>%
pull(four_hour_percent)
valueBox(scales::percent(four_hour_percent),
caption = paste("Patients at Type 1 EDs treated and discharged or admitted within 4 hours during",
last_month),
icon = "fa-clock",
color = "info",
href = "#all-types")
```
### Value Box 5
```{r value box 5}
total_12hrs <-
dat_graph %>%
filter(Date == max(Date)) %>%
summarise(total12 = sum(Over12hrs)) %>%
pull(total12)
valueBox(format(total_12hrs, big.mark = ","),
caption = paste("Waits over 12 hours during", last_month),
icon = "fa-exclamation-circle",
color = "primary",
href = "#all-types")
```
```{r logo, out.width = "175px", echo=FALSE, fig.align='centre'}
#knitr::include_graphics("C:/Users/1463231/Desktop/R/NISRA-acronym-bilingual_transparent.png")
#knitr::include_graphics("E:/ED Occupancy Forecasting/HIB Dashboard/data/IAD_transparent.png")
```
All Types {data-navmenu="Graphs" data-icon="fa-chart-line"}
===========================================================
Row {.tabset .tabset-fade}
-------------------------------------
### **Total Attendances by Trust**
```{r NI totals}
mycolors = c('#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#e377c2')
plot_ly(NI_totals,
x = ~Month,
y = ~TotalAttendances,
color = ~Trust,
type = 'scatter',
mode = 'lines',
line = list(width = 2.5),
colors = mycolors,
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Attendances:", format(TotalAttendances, big.mark = ",")
)) %>%
layout(title = "",
theme(plot.title = element_text(hjust = 0.1)),
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
annotations = list(x = 1, y = 0.01, text = "Hospital Information Branch",
showarrow = F, xref = 'paper', yref = 'paper',
xanchor = 'right', yanchor = 'auto', xshift = 0, yshift = 0,
font = list(size = 10, color = "grey")),
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "Total Attendances by Trust",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
#range = c(40,105),
tickformat = ",",
zeroline = FALSE))
```
### **Total Attendances by Type**
```{r attendance by type}
plot_ly(type1_totals,
x = ~Month,
y = ~Total,
name = 'Type 1',
type = 'scatter',
mode = 'lines',
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Total:", format(Total, big.mark = ",")),
visible = 'legendonly',
showlegend = TRUE,
line = list(width = 2.5)) %>%
add_trace(y = ~type2_totals$Total,
name = 'Type 2',
mode = 'lines',
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Total:", format(type2_totals$Total, big.mark = ",")),
visible = 'legendonly') %>%
add_trace(y = ~type3_totals$Total,
name = 'Type 3',
mode = 'lines',
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Total:", format(type3_totals$Total, big.mark = ",")),
visible = 'legendonly') %>%
add_trace(y = ~totalattend_df$Total,
name = 'Total Attendances',
mode = 'lines',
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Total:", format(totalattend_df$Total, big.mark = ",")),
visible = TRUE) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "Total Attendances",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
#range = c(40,105),
tickformat = ",",
zeroline = FALSE))
```
Row {.tabset .tabset-fade}
-------------------------------------
### **Under 4 Hours by Type**
```{r under 4 by type}
plot_ly(type1_totals,
x = ~Month,
y = ~Percentunder4,
name = 'Type 1',
type = 'scatter',
mode = 'lines',
showlegend = TRUE,
hoverinfo = "text",
text = ~paste0(
"", Month, "
",
"Type 1: ", Percentunder4*100,"%"),
line = list(width = 2.5)) %>%
add_trace(y = ~type2_totals$Percentunder4,
name = 'Type 2',
mode = 'lines',
visible = "legendonly",
hoverinfo = "text",
text = ~paste0(
"", Month, "
",
"Type 2: ", type2_totals$Percentunder4*100,"%")) %>%
add_trace(y = ~type3_totals$Percentunder4,
name = 'Type 3',
mode = 'lines',
visible = "legendonly",
hoverinfo = "text",
text = ~paste0(
"", Month, "
",
"Type 3: ", type3_totals$Percentunder4*100,"%")) %>%
add_trace(y = ~type1_totals$target,
name = '95% Target',
line = list(dash = 'dash'),
hoverinfo = "text",
text = ~paste0(
"", Month, "
",
"Target : ", target*100,"%")) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
annotations = list(x = 1, y = 0.01, text = "Hospital Information Branch",
showarrow = F, xref = 'paper', yref = 'paper',
xanchor = 'right', yanchor = 'auto', xshift = 0, yshift = 0,
font = list(size = 10, color = "grey")),
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "% Waiting Under 4hrs",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
range = c(0.40,1.05),
tickformat = "%",
zeroline = FALSE))
```
### **Over 12 Hours by Type**
```{r over 12 by type}
plot_ly(type1_totals,
x = ~Month,
y = ~Over12,
name = 'Type 1',
type = 'scatter',
mode = 'lines',
fill = 'tozeroy',
fillcolor = 'tozeroy',
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Type 1:", format(Over12, big.mark = ",")),
showlegend = TRUE,
line = list(width = 2.5)) %>%
add_trace(y = ~type2_totals$Over12,
name = 'Type 2',
mode = 'lines',
fill = 'tozeroy',
fillcolor = 'tozeroy',
text = ~paste(
"", Month, "
",
"Type 2:", format(type2_totals$Over12, big.mark = ",")),
visible = "legendonly") %>%
add_trace(y = ~type3_totals$Over12,
name = 'Type 3',
mode = 'lines',
fill = 'tozeroy',
fillcolor = 'tozeroy',
text = ~paste(
"", Month, "
",
"Type 3:", format(type3_totals$Over12, big.mark = ",")),
visible = "legendonly") %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "No Waiting Over 12hrs",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
#range = c(40,105),
tickformat = ",",
zeroline = FALSE))
```
Type 1 EDs {data-navmenu="Graphs" data-icon="fa-chart-line"}
===========================================================
Row {.tabset .tabset-fade}
-------------------------------------
### **Attendances - Type 1**
```{r attendances type1}
plot_ly(type1_totals,
x = ~Month,
y = ~Total,
name = 'Attendances',
type = 'scatter',
mode = 'lines',
fill = 'tozeroy',
fillcolor = 'tozeroy',
showlegend = TRUE,
hoverinfo = "text",
text = ~paste(
"", Month, "
",
"Attendances:", format(Total, big.mark = ",")),
line = list(width = 2.5)) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
annotations = list(x = 1, y = 0.01, text = "Hospital Information Branch",
showarrow = F, xref = 'paper', yref = 'paper',
xanchor = 'right', yanchor = 'auto', xshift = 0, yshift = 0,
font = list(size = 10, color = "white")),
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "Attendances",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
range = c(0,80000),
tickformat = ",",
zeroline = FALSE))
```
### **EDs - Type 1**
```{r eds type1}
plot_ly(totalattend_df_type1, x = ~Month, y = ~Mater, name = 'Mater', type = 'scatter', mode = 'lines', showlegend = TRUE, line = list(width = 2.5),
hoverinfo = "text", text = ~paste("", Month, "
", "Mater:", format(Mater, big.mark = ","))) %>%
add_trace(y = ~RVH, name = 'RVH', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "RVH:", format(RVH, big.mark = ","))) %>%
add_trace(y = ~RBHSC, name = 'RBHSC', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "RBHSC:", format(RBHSC, big.mark = ","))) %>%
add_trace(y = ~`Belfast City`, name = 'Belfast City', mode = 'lines', visible = 'legendonly', hoverinfo = "text",
text = ~paste("", Month, "
", "Belfast City:", format(`Belfast City`, big.mark = ","))) %>%
add_trace(y = ~`Antrim Area`, name = 'Antrim', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Antrim Area:", format(`Antrim Area`, big.mark = ","))) %>%
add_trace(y = ~Causeway, name = 'Causeway', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Causeway:", format(Causeway, big.mark = ","))) %>%
add_trace(y = ~Ulster, name = 'Ulster', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Ulster:", format(Ulster, big.mark = ","))) %>%
add_trace(y = ~`Craigavon Area`, name = 'Craigavon', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Craigavon:", format(`Craigavon Area`, big.mark = ","))) %>%
add_trace(y = ~`Daisy Hill`, name = 'Daisy Hill', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Daisy Hill:", format(`Daisy Hill`, big.mark = ","))) %>%
add_trace(y = ~`Altnagelvin Area`, name = 'Altnagelvin', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "Altnagelvin:", format(`Altnagelvin Area`, big.mark = ","))) %>%
add_trace(y = ~`South West Acute`, name = 'SWA', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste("", Month, "
", "SWA:", format(`South West Acute`, big.mark = ","))) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
annotations = list(x = 1, y = 0.01, text = "Hospital Information Branch",
showarrow = F, xref = 'paper', yref = 'paper',
xanchor = 'right', yanchor = 'auto', xshift = 0, yshift = 0,
font = list(size = 10, color = "grey")),
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "Attendances",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
range = c(1000,9500),
tickformat = ",",
zeroline = FALSE))
```
Row {.tabset .tabset-fade}
-------------------------------------
### **Under 4 Hours - Type 1**
```{r eds under 4}
plot_ly(under4hrs_df, x = ~Month, y = ~Mater, name = 'Mater', type = 'scatter', mode = 'lines', showlegend = TRUE, line = list(width = 2.5),
hoverinfo = "text", text = ~paste0("", Month, "
", "Mater: ", Mater*100, "%")) %>%
add_trace(y = ~RVH, name = 'RVH', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "RVH: ", RVH*100, "%")) %>%
add_trace(y = ~RBHSC, name = 'RBHSC', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "RBHSC: ", RBHSC*100, "%")) %>%
add_trace(y = ~`Belfast City`, name = 'Belfast City', mode = 'lines', visible = 'legendonly', hoverinfo = "text",
text = ~paste0("", Month, "
", "Belfast City: ", `Belfast City`*100, "%")) %>%
add_trace(y = ~`Antrim Area`, name = 'Antrim', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Antrim Area: ", `Antrim Area`*100, "%")) %>%
add_trace(y = ~Causeway, name = 'Causeway', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Causeway: ", Causeway*100, "%")) %>%
add_trace(y = ~Ulster, name = 'Ulster', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Ulster: ", Ulster*100, "%")) %>%
add_trace(y = ~`Craigavon Area`, name = 'Craigavon', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Craigavon: ", `Craigavon Area`*100, "%")) %>%
add_trace(y = ~`Daisy Hill`, name = 'Daisy Hill', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Daisy Hill: ", `Daisy Hill`*100, "%")) %>%
add_trace(y = ~`Altnagelvin Area`, name = 'Altnagelvin', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "Altnagelvin: ", `Altnagelvin Area`*100, "%")) %>%
add_trace(y = ~`South West Acute`, name = 'SWA', mode = 'lines', visible = "legendonly", hoverinfo = "text",
text = ~paste0("", Month, "
", "SWA: ", `South West Acute`*100, "%")) %>%
add_trace(y = ~type1_totals$target, name = '95% Target', line = list(color = 'rgb(205, 12, 24)', dash = 'dash'),
hoverinfo = "text", text = ~paste0("", Month, "
", "Target: ", type1_totals$target*100, "%")) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
annotations = list(x = 1, y = 0.01, text = "Hospital Information Branch",
showarrow = F, xref = 'paper', yref = 'paper',
xanchor = 'right', yanchor = 'auto', xshift = 0, yshift = 0,
font = list(size = 10, color = "grey")),
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 7,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "% Waiting Under 4hrs",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,299)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
range = c(0.4,1.05),
tickformat = "%",
zeroline = FALSE))
```
### **Over 12 Hours - Type 1**
```{r eds over 12}
plot_ly(over12hrs_df, x = ~Month, y = ~Mater, name = 'Mater', type = 'scatter', mode = 'lines',
fill = 'tozeroy', fillcolor = 'tozeroy', showlegend = TRUE, line = list(width = 2.5),
hoverinfo = "text", text = ~paste("", Month, "
", "Mater:", format(Mater, big.mark = ","))) %>%
add_trace(y = ~RVH, name = 'RVH', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "RVH:", format(RVH, big.mark = ","))) %>%
add_trace(y = ~RBHSC, name = 'RBHSC', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "RBHSC:", format(RBHSC, big.mark = ","))) %>%
add_trace(y = ~`Belfast City`, name = 'Belfast City', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Belfast City:", format(`Belfast City`, big.mark = ","))) %>%
add_trace(y = ~`Antrim Area`, name = 'Antrim', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Antrim:", format(`Antrim Area`, big.mark = ","))) %>%
add_trace(y = ~Causeway, name = 'Causeway', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Causeway:", format(Causeway, big.mark = ","))) %>%
add_trace(y = ~Ulster, name = 'Ulster', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Ulster:", format(Ulster, big.mark = ","))) %>%
add_trace(y = ~`Craigavon Area`, name = 'Craigavon', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Craigavon:", format(`Craigavon Area`, big.mark = ","))) %>%
add_trace(y = ~`Daisy Hill`, name = 'DaisyHill', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Daisy Hill:", format(`Daisy Hill`, big.mark = ","))) %>%
add_trace(y = ~`Altnagelvin Area`, name = 'Altnagelvin', mode = 'lines',visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "Altnagelvin:", format(`Altnagelvin Area`, big.mark = ","))) %>%
add_trace(y = ~`South West Acute`, name = 'SWA', mode = 'lines', visible = 'legendonly', fill = 'tozeroy', fillcolor = 'tozeroy',
hoverinfo = "text", text = ~paste("", Month, "
", "SWA:", format(`South West Acute`, big.mark = ","))) %>%
layout(title = "",
paper_bgcolor = 'rgb(255,255,255)', plot_bgcolor = 'rgb(255,255,255)',
xaxis = list(title = "",
gridcolor = 'rgb(255,255,255)',
showgrid = FALSE,
showline = TRUE,
#dtick = 4,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "No. Waiting Over 12hrs",
titlefont = list(size = 11),
gridcolor = 'rgb(229,229,229)',
showgrid = TRUE,
showline = TRUE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
range = c(0,800),
zeroline = FALSE))
# Michael O'Donnell
# Hospital Information Branch
# Information & Analysis Directorate
# NISRA
```