Skip to content

Commit 23f84f9

Browse files
authored
Merge pull request #41 from The-Strategy-Unit/28-nee
Add NEE plot
2 parents 10a1caa + 78be343 commit 23f84f9

File tree

8 files changed

+198
-3
lines changed

8 files changed

+198
-3
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(generate_rates_baseline_data)
77
export(generate_rates_funnel_data)
88
export(isolate_provider_peers)
99
export(plot_age_sex_pyramid)
10+
export(plot_nee)
1011
export(plot_rates_box)
1112
export(plot_rates_funnel)
1213
export(plot_rates_trend)

R/app_server.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ app_server <- function(input, output, session) {
3030
data_version
3131
) |>
3232
prepare_age_sex_data()
33+
nee_data <- readr::read_csv(
34+
app_sys("app", "data", "nee_table.csv"),
35+
col_types = "cddd"
36+
)
3337

3438
# Lookups ----
3539
providers_lookup <- jsonlite::read_json(
@@ -103,4 +107,9 @@ app_server <- function(input, output, session) {
103107
selected_strategy,
104108
start_year
105109
)
110+
mod_plot_nee_server(
111+
"mod_plot_nee",
112+
nee_data,
113+
selected_strategy
114+
)
106115
}

R/app_ui.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ app_ui <- function(request) {
3636
mod_table_procedures_ui("mod_table_procedures"),
3737
mod_table_diagnoses_ui("mod_table_diagnoses")
3838
),
39-
mod_plot_age_sex_pyramid_ui("mod_plot_age_sex_pyramid"),
39+
bslib::layout_column_wrap(
40+
width = 1 / 2,
41+
mod_plot_age_sex_pyramid_ui("mod_plot_age_sex_pyramid"),
42+
mod_plot_nee_ui("mod_plot_nee")
43+
),
4044
)
4145
)
4246
)

R/fct_plots.R

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,38 @@ plot_age_sex_pyramid <- function(age_sex_data) {
156156
panel.background = ggplot2::element_blank()
157157
)
158158
}
159+
160+
#' Plot National Elicitation Exercise (NEE) Interval
161+
#' @param nee_data A data.frame. Mean, p10 and p90 predictions for each of the
162+
#' strategies that were part of the National Elicitation Exercise (NEE),
163+
#' filtered for the user's selected strategy.
164+
#' @return A 'ggplot2' object.
165+
#' @export
166+
plot_nee <- function(nee_data) {
167+
nee_data |>
168+
ggplot2::ggplot() +
169+
ggplot2::geom_segment(
170+
ggplot2::aes(
171+
y = 1,
172+
yend = 1,
173+
x = .data[["percentile10"]],
174+
xend = .data[["percentile90"]]
175+
),
176+
size = 2
177+
) +
178+
ggplot2::geom_point(
179+
ggplot2::aes(y = 1, x = mean),
180+
size = 5,
181+
colour = "#f9bf14"
182+
) +
183+
ggplot2::xlim(0, 100) +
184+
ggplot2::xlab(
185+
"80% prediction interval"
186+
) +
187+
ggplot2::theme_minimal() +
188+
ggplot2::theme(
189+
axis.title.y = ggplot2::element_blank(),
190+
axis.text.y = ggplot2::element_blank(),
191+
axis.ticks.y = ggplot2::element_blank()
192+
)
193+
}

R/mod_plot_age_sex_pyramid.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Plot Age-Sex Pyramid Trend UI
1+
#' Plot Age-Sex Pyramid UI
22
#' @param id,input,output,session Internal parameters for `shiny`.
33
#' @noRd
44
mod_plot_age_sex_pyramid_ui <- function(id) {
@@ -12,7 +12,9 @@ mod_plot_age_sex_pyramid_ui <- function(id) {
1212

1313
#' Plot Age-Sex Pyramid Server
1414
#' @param id Internal parameter for `shiny`.
15-
#' @param age_sex_data A data.frame.
15+
#' @param age_sex_data A data.frame. Age-sex data read from Azure and processed
16+
#' with [prepare_age_sex_data]. Counts for each strategy split by provider,
17+
#' year, age group and sex.
1618
#' @param selected_provider Character. Provider code, e.g. `"RCF"`.
1719
#' @param selected_strategy Character. Strategy variable name, e.g.
1820
#' `"alcohol_partially_attributable_acute"`.

R/mod_plot_nee.R

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#' Plot National Elicitation Exercise (NEE) UI
2+
#' @param id,input,output,session Internal parameters for `shiny`.
3+
#' @noRd
4+
mod_plot_nee_ui <- function(id) {
5+
ns <- shiny::NS(id)
6+
bslib::card(
7+
bslib::card_header("National Elicitation Exercise (NEE) estimate"),
8+
bslib::card_body(
9+
shiny::p("2039/40 horizon. Mean represented as a point."),
10+
shiny::plotOutput(ns("nee"))
11+
),
12+
full_screen = TRUE
13+
)
14+
}
15+
16+
#' Plot National Elicitation Exercise (NEE) Server
17+
#' @param id Internal parameter for `shiny`.
18+
#' @param nee_data A data.frame. Mean, p10 and p90 predictions for each of the
19+
#' strategies that were part of the National Elicitation Exercise (NEE).
20+
#' @param selected_strategy Character. Strategy variable name, e.g.
21+
#' `"alcohol_partially_attributable_acute"`.
22+
#' @noRd
23+
mod_plot_nee_server <- function(id, nee_data, selected_strategy) {
24+
shiny::moduleServer(id, function(input, output, session) {
25+
output$nee <- shiny::renderPlot({
26+
shiny::req(nee_data)
27+
shiny::req(selected_strategy())
28+
29+
nee_filtered <- nee_data |>
30+
dplyr::filter(.data$param_name == selected_strategy())
31+
32+
shiny::validate(
33+
shiny::need(
34+
nrow(nee_filtered) > 0,
35+
paste(
36+
"This type of potentially-mitigatable activity (TPMA) was not part",
37+
"of the National Elicitation Exercise (NEE), so a",
38+
"nationally-determined estimate is not available."
39+
)
40+
)
41+
)
42+
43+
plot_nee(nee_filtered)
44+
})
45+
})
46+
}

inst/app/data/nee_table.csv

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
param_name,mean,percentile10,percentile90
2+
alcohol_partially_attributable_acute,76.58944231,97.522619072,39.92057311
3+
alcohol_partially_attributable_chronic,82.59142828,97.901963857,60.15757977
4+
alcohol_wholly_attributable,85.0659187,98.149701993,59.03811113
5+
ambulatory_care_conditions_acute,76.24602055,97.072034229,43.62456672
6+
ambulatory_care_conditions_chronic,75.1070788,97.099716303,40.98916714
7+
ambulatory_care_conditions_vaccine_preventable,77.79454286,97.33633513,51.67388443
8+
cancelled_operations,67.50577683,93.232250496,34.67371174
9+
consultant_to_consultant_reduction_adult_non-surgical,81.31492171,97.607544624,58.15165521
10+
consultant_to_consultant_reduction_adult_surgical,78.47617512,97.10820316,53.5564793
11+
consultant_to_consultant_reduction_child_non-surgical,77.30875592,95.797931765,47.26119919
12+
consultant_to_consultant_reduction_child_surgical,79.96715146,97.746921503,49.384977
13+
eol_care_2_days,72.08778414,93.711962536,34.55226822
14+
eol_care_3_to_14_days,79.58371663,95.29097698,50.34811687
15+
evidence_based_interventions_ent,53.7137119,88.18222051000001,23.343624759999997
16+
evidence_based_interventions_general_surgery,59.75999705,88.72084248,27.218407420000005
17+
evidence_based_interventions_gi_surgical,79.80727829,96.77784566,52.78199892
18+
evidence_based_interventions_msk,54.63154433,89.26653856,21.632259450000006
19+
evidence_based_interventions_urology,63.28482667,96.286206815,25.842634250000003
20+
evidence_based_interventions_vascular_varicose_veins,51.72728761,80.17961008,21.427971330000005
21+
falls_related_admissions,85.91059503,98.714915386,56.9348065
22+
followup_reduction_adult_non-surgical,65.8700221,95.963139315,37.06084141
23+
followup_reduction_adult_surgical,74.89754465,97.148738244,42.56895136
24+
followup_reduction_child_non-surgical,82.4832679,96.43517932,59.98113701
25+
followup_reduction_child_surgical,83.58469765,97.580519792,59.52655234
26+
frail_elderly_high,94.286779628,99.566766036,83.60301915
27+
frail_elderly_intermediate,91.364883775,99.105768203,79.20168105
28+
frequent_attenders_adult_ambulance,75.3611344,94.799458238,44.16653032
29+
frequent_attenders_adult_walk-in,81.2851926,96.046881706,60.8844789
30+
frequent_attenders_child_ambulance,77.38495492,97.226619794,46.82339375
31+
frequent_attenders_child_walk-in,79.26598771,98.305595653,55.98949325
32+
intentional_self_harm,81.67292674000001,97.928465846,47.64351967
33+
left_before_seen_adult_ambulance,75.3004681,95.805192719,48.02266528
34+
left_before_seen_adult_walk-in,67.58141287000001,97.101765727,34.94430088
35+
left_before_seen_child_ambulance,69.36482781000001,97.600743381,30.282850120000006
36+
left_before_seen_child_walk-in,67.09085801,96.878226063,29.537754059999997
37+
low_cost_discharged_adult_ambulance,69.19920015,93.250010645,40.10873193
38+
low_cost_discharged_adult_walk-in,74.74368538,94.930529676,46.24473746
39+
low_cost_discharged_child_ambulance,77.45914761,99.119960209,47.99677245
40+
low_cost_discharged_child_walk-in,74.84101392,96.647851157,43.82014639
41+
medically_unexplained_related_admissions,86.66933198,98.833527985,61.18022795
42+
medicines_related_admissions_explicit,84.25453041,97.64432614,63.04745688
43+
medicines_related_admissions_implicit_anti-diabetics,70.55096483,95.365109631,37.57622131
44+
medicines_related_admissions_implicit_benzodiasepines,87.26251081,99.474566688,67.52574745999999
45+
medicines_related_admissions_implicit_diurectics,83.18944655,98.960862358,59.21627277
46+
medicines_related_admissions_implicit_nsaids,81.16312970999999,97.633663525,50.31294376
47+
obesity_related_admissions,84.8284795,98.01943932,55.38353287
48+
raid_ae,85.22909305,98.071842811,54.76825345
49+
readmission_within_28_days,83.58979633,95.945934349,63.43411212
50+
smoking,84.31463664,98.866721497,59.98338837
51+
zero_los_no_procedure_adult,75.14857705,97.525543798,45.84957177
52+
zero_los_no_procedure_child,80.38631547,97.527397217,55.13509122
53+
ambulatory_emergency_care_high,75.01179258,98.689093994,48.04697702
54+
ambulatory_emergency_care_low,75.12936268,96.049267586,30.65241107
55+
ambulatory_emergency_care_moderate,72.72610633,95.852054072,46.86872646
56+
ambulatory_emergency_care_very_high,64.73960328999999,96.588934437,35.099254599999995
57+
bads_daycase,63.98887742,86.73551731,34.060803910000004
58+
bads_daycase_occasional,70.46212414,94.797805858,35.836390030000004
59+
bads_outpatients,55.49104095,85.66413771,19.393883939999995
60+
bads_outpatients_or_daycase,62.6896898,89.0882033,30.06155769
61+
emergency_elderly,82.59806635,96.043510115,60.72989743
62+
enhanced_recovery_bladder,65.80176370000001,91.33441839,34.41313542
63+
enhanced_recovery_breast,60.18595809,94.287937957,22.834143170000004
64+
enhanced_recovery_colectomy,76.46814446,94.72628511,50.59516639
65+
enhanced_recovery_hip,58.96483906,92.930259893,29.274554780000003
66+
enhanced_recovery_hysterectomy,71.68937628,95.331232806,33.339561520000004
67+
enhanced_recovery_knee,60.8460233,92.154957577,29.243783300000004
68+
enhanced_recovery_prostate,69.56661841,92.219803903,39.67523539
69+
enhanced_recovery_rectum,77.87659980000001,95.403201969,51.79233086
70+
excess_beddays_elective,76.61621966,97.018275735,44.98583541
71+
excess_beddays_emergency,72.70341937,96.906496976,44.20408294
72+
pre-op_los_1-day,54.08834037,82.27572568,27.102307390000007
73+
pre-op_los_2-day,54.08834037,82.27572568,27.102307390000007
74+
raid_ip,84.58657373,96.948584232,52.34138682
75+
stroke_early_supported_discharge,82.03253305999999,96.659841453,55.38388199
76+
convert_to_tele_adult_surgical,66.81130907,91.339844732,31.50170097
77+
convert_to_tele_adult_non-surgical,68.98469495,92.89879779500001,34.39320196
78+
convert_to_tele_child_surgical,72.13793377,90.041605519,46.19841365
79+
convert_to_tele_child_non-surgical,72.58843795,91.794797295,44.53912826

man/plot_nee.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)