generated from nhsx/open-analytics-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.Rhistory
512 lines (512 loc) · 25.6 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)
) %>%
addPolygons(
data=stp_spdf,
group="ICS boundary",
fillOpacity=0.1,
color='black',
weight=2,
label=mytext_ics
) %>%
#addLegend( data=ccg_spdf,pal=catpal, values=~Short.Status, opacity=0.9, title = "21/22 DSPT Status (CCG)", position = "bottomleft" ) %>%
leaflet::addLayersControl(
overlayGroups = c("CCG","ICS boundary"), # add these layers
options = layersControlOptions(collapsed = FALSE) # expand on hover?
) %>%
hideGroup(c("ICS boundary")) # turn these off by default
m02_l <- m02 %>% addLegend( data=ccg_spdf,pal=catpal, values=~Short.Status, opacity=0.9, title = "21/22 DSPT Status (CCG)", position = "bottomleft" )
#############################################
# Mapping - CCGS + ICS + trust layer
#############################################
get_popup_content <- function(my_spdf) {
paste0(
"<b>Provider </b>",
"<br><b>- Provider code</b>:", my_spdf@data$ODS.Code,
"<br><b>- Provider name:</b> ", my_spdf@data$ODS.Org.Name,
#"<br><b>- STP/ICS (HQ postcode-based):</b> ", my_spdf@data$STP20NM,
#"<br><b>- Region:</b> ", my_spdf@data$`NHSER20NM`,
"<br><b>- DSPT status:</b> ", my_spdf@data$Status,
sep=""
)
}
m03 <- m02_l %>%
addCircleMarkers(data=trust_spdf_points,
group="Trusts",
label = ~ lapply(get_popup_content(trust_spdf_points), htmltools::HTML),
fillColor = ~catpal(Status),
color="black",
weight=2,
fillOpacity = 1,
stroke = T,
#clusterOptions = markerClusterOptions(),
radius= 6)
#m03
#adding the zoom toggle for trust level (trust layer appears between 9 and 20)
#m03 <- m03 %>%
# groupOptions("Trusts", zoomLevels = 9:20)
#adding legend and layering CCG trusts and ICG boundary together
m03 <- m03 %>%
addLegend( data=trust_spdf_points,pal=catpal, values=~Status, opacity=0.9, title = "21/22 DSPT Status (trust)", position = "bottomright" ) %>%
leaflet::addLayersControl(
overlayGroups = c("ICS boundary","CCG","Trusts"), # add these layers
options = layersControlOptions(collapsed = FALSE) # expand on hover?
) %>%
hideGroup(c("ICS boundary","Trusts")) # turn these off by default
#############################################
# Summary metric
#############################################
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
View(trusts_data2)
trusts_data_merged = left_join(trusts_data2, etr)
View(trusts_data_merged)
trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = left_join(trusts_data2, etr)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
View(trusts_data_merged)
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
View(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified.csv')
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
View(ect)
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect)
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
#############################################
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect)
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect)
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect, by = 'ODS.Code')
#############################################
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect, by = 'ODS.Code')
View(etr)
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
#get the final 4 stp codes of the 4 care trusts from ect (modified to change column names and select relevant columns)
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
etr_ect = rbind(etr, ect)
View(etr_ect)
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr_ect)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
#merge the final 4 care trusts with trustsdatamerged
trusts_data_merged = left_join(trusts_data_merged, ect, by = 'ODS.Code')
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
#get the final 4 stp codes of the 4 care trusts from ect (modified to change column names and select relevant columns)
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
etr_ect = rbind(etr, ect)
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr_ect)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
region_codes = unique(select(data_ccg, 'STP21CD' = 'STP21CD', 'NHSER22NM' = 'NHSER22NM'))
trusts_data_merged = left_join(trusts_data_merged, region_codes)
data_ccg$Sector = 'CCG'
data_ccg = select(data_ccg, 'ODS.Code' = 'ODS.Code', 'ODS.Org.Name' = 'LOC22NM', 'Status' = 'Status', 'Sector' = 'Sector', 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM', 'NHSER22NM' = 'NHSER22NM')
data_joint <- rbind(data_ccg, trusts_data_merged)
data_metric <- data_joint %>% filter(Sector %in% c("Trust","CCG"))
data_metric <- data_joint %>% filter(Sector %in% c("Trust"))
View(data_metric)
unique(data_metric$ODS.Code)
View(data_regions)
trusts_data_merged = left_join(trusts_data_merged, data_regions)
#############################################
#get the stp codes for trusts from etr
etr = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/etr.csv', header = FALSE)
etr = etr[,c('V1', 'V4')]
etr = select(etr, 'ODS.Code' = 'V1', 'STP21CDH' = 'V4')
#get the final 4 stp codes of the 4 care trusts from ect (modified to change column names and select relevant columns)
ect = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/ect_modified_21_22.csv')
ect = select(ect, 'ODS.Code', 'STP21CDH')
etr_ect = rbind(etr, ect)
trusts_data2 = trusts_data
trusts_data2$Sector = 'Trust'
trusts_data_merged = left_join(trusts_data2, etr_ect)
#trusts_data_merged = na.omit(trusts_data_merged)
trusts_data_merged = select(trusts_data_merged, c('ODS.Code', 'ODS.Org.Name', 'Status', 'Sector', 'STP21CDH'))
data_ccg = data_merged
stp_codes = select(data_ccg, 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM')
stp_codes = unique(stp_codes)
trusts_data_merged = left_join(trusts_data_merged, stp_codes)
#load in ccg-stp-region lookup data
regions_lookup = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/Clinical_Commissioning_Group_to_STP_and_NHS_England_(Region)_(April_2021)_Lookup_in_England.csv')
data_regions = unique(select(regions_lookup, 'STP21CD', 'STP21NM', 'NHSER21NM'))
trusts_data_merged = left_join(trusts_data_merged, data_regions)
unique(trusts_data_merged)
unique(trusts_data_merged$ODS.Code)
data_ccg$Sector = 'CCG'
data_ccg = select(data_ccg, 'ODS.Code' = 'ODS.Code', 'ODS.Org.Name' = 'LOC22NM', 'Status' = 'Status', 'Sector' = 'Sector', 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM', 'NHSER22NM' = 'NHSER22NM')
data_joint <- rbind(data_ccg, trusts_data_merged)
View(data_ccg)
data_ccg$Sector = 'CCG'
data_ccg = select(data_ccg, 'ODS.Code' = 'ODS.Code', 'ODS.Org.Name' = 'LOC22NM', 'Status' = 'Status', 'Sector' = 'Sector', 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM', 'NHSER21NM' = 'NHSER22NM')
data_ccg = data_merged
data_ccg$Sector = 'CCG'
data_ccg = select(data_ccg, 'ODS.Code' = 'ODS.Code', 'ODS.Org.Name' = 'LOC22NM', 'Status' = 'Status', 'Sector' = 'Sector', 'STP21CD' = 'STP21CD', 'STP21CDH' = 'STP21CDH', 'STP21NM' = 'STP21NM', 'NHSER21NM' = 'NHSER22NM')
data_joint <- rbind(data_ccg, trusts_data_merged)
data_metric <- data_joint %>% filter(Sector %in% c("Trust","CCG"))
data_metric <- data_joint %>% filter(Sector %in% c("Trust"))
gppopdata <- read_csv("https://files.digital.nhs.uk/62/79B56F/gp-reg-pat-prac-sing-age-regions.csv")
gppopdata_red <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="SUB_ICB_LOCATION") %>% select(c("ORG_CODE","NUMBER_OF_PATIENTS"))
# score mapping
data_metric <- data_metric %>% mutate(Status.Score=case_when(Status=="21/22 Standards Exceeded"~3,
Status=="21/22 Standards Met"~1,
Status=="21/22 Approaching Standards"~-1,
Status=="21/22 Standards Not Met"~-3,
Status=="21/22 Not Published"~-3))
NUMBER_OF_PATIENTS = gppopdata['NUMBER_OF_PATIENTS']
data_metric <- data_metric %>% left_join(gppopdata_red,by=c("ODS.Code"="ORG_CODE")) #TRUE~NA_integer_))
data_metric_ICS <- data_metric %>% group_by(STP21CDH, STP21CD, Sector) %>% summarise(Simple.Score=mean(Status.Score,na.rm=T),
Simple.n=n(),
Pop.Score=sum(NUMBER_OF_PATIENTS*Status.Score)/sum(NUMBER_OF_PATIENTS))
data_metric_ICS <- data_metric_ICS %>% pivot_wider(names_from=Sector,values_from=c("Simple.Score","Simple.n","Pop.Score"))
data_metric_ICS <- data_metric_ICS %>% mutate(metric_CCG_simple = Simple.Score_CCG,
metric_CCG_pop = Pop.Score_CCG,
metric_CCGTrust_simple = 0.5*Simple.Score_CCG+0.5*Simple.Score_Trust,
metric_CCGp_Trusts =0.5*Pop.Score_CCG+0.5*Simple.Score_Trust)
data_metric <- data_joint %>% filter(Sector %in% c("Trust","CCG"))
# GP practice population
# https://digital.nhs.uk/data-and-information/publications/statistical/patients-registered-at-a-gp-practice/september-2022
gppopdata <- read_csv("https://files.digital.nhs.uk/62/79B56F/gp-reg-pat-prac-sing-age-regions.csv")
gppopdata_red <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="SUB_ICB_LOCATION") %>% select(c("ORG_CODE","NUMBER_OF_PATIENTS"))
# score mapping
data_metric <- data_metric %>% mutate(Status.Score=case_when(Status=="21/22 Standards Exceeded"~3,
Status=="21/22 Standards Met"~1,
Status=="21/22 Approaching Standards"~-1,
Status=="21/22 Standards Not Met"~-3,
Status=="21/22 Not Published"~-3))
NUMBER_OF_PATIENTS = gppopdata['NUMBER_OF_PATIENTS']
data_metric <- data_metric %>% left_join(gppopdata_red,by=c("ODS.Code"="ORG_CODE")) #TRUE~NA_integer_))
data_metric_ICS <- data_metric %>% group_by(STP21CDH, STP21CD, Sector) %>% summarise(Simple.Score=mean(Status.Score,na.rm=T),
Simple.n=n(),
Pop.Score=sum(NUMBER_OF_PATIENTS*Status.Score)/sum(NUMBER_OF_PATIENTS))
data_metric_ICS <- data_metric_ICS %>% pivot_wider(names_from=Sector,values_from=c("Simple.Score","Simple.n","Pop.Score"))
data_metric_ICS <- data_metric_ICS %>% mutate(metric_CCG_simple = Simple.Score_CCG,
metric_CCG_pop = Pop.Score_CCG,
metric_CCGTrust_simple = 0.5*Simple.Score_CCG+0.5*Simple.Score_Trust,
metric_CCGp_Trusts =0.5*Pop.Score_CCG+0.5*Simple.Score_Trust)
stp_spdf@data <- stp_spdf@data %>% left_join(data_metric_ICS,by=c("STP21CD"="STP21CD"))
stp_data = stp_spdf@data
# Create a continuous palette function
# Create a continuous palette function in our desired range (+3 - 3)
# Create a continuous palette function in our desired range (+3 - 3)
pal_metric <- colorNumeric(
palette = "RdYlBu",
domain = range(-3:3))
#create the label text for the first composite map
mytext_ics_score <- paste(
"<b>STP code (ODS): </b>", stp_spdf@data$STP21CD,"<br/>",
"<b>STP name (ODS): </b>", stp_spdf@data$STP21NM,"<br/>",
"<b>ICS score (CCG+Trust simple), range [-3,3]: </b>",round(stp_spdf@data$metric_CCGp_Trusts,2),"<br/>",
sep="") %>%
lapply(htmltools::HTML)
#create the label text to display the stp info for each polygon
mytext_new <- paste(
"<b>STP code (ODS): </b>", stp_spdf@data$STP21CD,"<br/>",
"<b>STP name (ODS): </b>", stp_spdf@data$STP21NM,"<br/>",
"<b>Region: </b>", stp_spdf@data$NHSER21NM,"<br/>",
"<b>ICS score (CCG population + Trust simple), range [-3,3]: </b>",round(stp_spdf@data$metric_CCGp_Trusts,2),"<br/>",
sep="") %>%
lapply(htmltools::HTML)
#create the map using map panes
#add a layer for the ICS colour coded polygons
#add a layer for empty ICS polygons with just the labels (this has the highest zindex - will be the top layer)
#add a layer for the region boundaries to be displayed in blue
m04 = leaflet() %>%
addMapPane(name = "regionBorder", zIndex = 425) %>%
addMapPane(name = "ICS polygons", zIndex = 400) %>%
addMapPane(name = "ICS Labels", zIndex = 450) %>%
addPolygons(
data=regions_spdf,
group="Region boundary",
fillOpacity=0,
color='blue',
weight=5,
options = leafletOptions(pane = "regionBorder")
) %>%
addTiles() %>%
setView( lat=53, lng=-2 , zoom=6) %>%
addPolygons(
data=stp_spdf,
group="ICS",
fillOpacity=1,
fillColor=~pal_metric(metric_CCGp_Trusts),
color="black",
weight=1,
options = leafletOptions(pane = "ICS polygons")) %>%
addPolygons(
data=stp_spdf,
group="ICS",
fillOpacity=0,
fillColor=~pal_metric(metric_CCGp_Trusts),
color="black",
weight= 0,
options = leafletOptions(pane = "ICS Labels"),
label = mytext_new ) %>%
addLegend("bottomright",pal=pal_metric,values=-3:3,title="ICS score - CCG population/Trust simple")
m04
#load in the data and filter for trusts changing the statuses to numerical values
data_trusts = data_joint %>% filter(Sector %in% c("Trust"))
#data_trusts <- data_trusts[c("ODS.Code", "ODS.Org.Name", "STP21CD", "Status")]
#change all the instances of each dspt score to 1 so this can be summed as a numerical tally to make the charts
data_trusts<- data_trusts %>% mutate(Standards_Met = case_when(Status == "21/22 Standards Met"~1,
TRUE ~ 0))
data_trusts<- data_trusts %>% mutate(Standards_Exceeded = case_when(Status == "21/22 Standards Exceeded"~1,
TRUE ~ 0))
data_trusts<- data_trusts %>% mutate(Standards_Not_Met = case_when(Status == "21/22 Standards Not Met"~1,
TRUE ~ 0))
data_trusts<- data_trusts %>% mutate(Approaching_Standards = case_when(Status == "21/22 Approaching Standards"~1,
TRUE ~ 0))
#select the relevant columns only
data_trusts = data_trusts[,c("STP21CD", "Standards_Met", "Standards_Exceeded", "Standards_Not_Met", "Approaching_Standards")]
#get the sum of each DSPT metric in separate columns grouped by each STP
#data_trusts_aggregate = data_trusts %>% group_by(STP21CD) %>% summarise_each(funs(sum))
data_trusts_aggregate = data_trusts %>% group_by(STP21CD) %>% summarise_at(vars(Standards_Met, Standards_Exceeded, Standards_Not_Met, Approaching_Standards), funs(sum))
#data_trusts_aggregate = data_trusts_aggregate %>% rename("STP21CD" = 1)
#wrangle teh GP population data to be used as the diameter for each of the mini piecharts
stp_filter_numpatients <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="ICB")
#stp_filter_numpatients <- stp_filter_numpatients %>% rename("STP21CD" = 5)
stp_filter_numpatients <- stp_filter_numpatients[c("STP21CD", "NUMBER_OF_PATIENTS")]
#merge together the separated dspt data with the gp population data and stp spatial data frame for mapping
data_trust_spdf_pie = left_join(x = stp_spdf@data, y = data_trusts_aggregate, by = "STP21CD")
gppopdata_blue <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="ICB") %>% select(c("ONS_CODE","NUMBER_OF_PATIENTS"))
gppopdata_blue <- gppopdata_blue %>% rename("STP21CD" = 1)
stp_spdfdata <- stp_spdf@data
stp_spdfdata1 = merge(stp_spdfdata, gppopdata_blue, by = "STP21CD")
#stp_spdf$data <- stp_spdfdata1
num_patients_stp <- gppopdata_blue[c("NUMBER_OF_PATIENTS")]
minpatients <- min(num_patients_stp)
maxpatients <- max(num_patients_stp)
patients_stps <- stp_spdfdata$data.NUMBER_OF_PATIENTS
pal_metric2 <- colorNumeric(
palette = "Blues",
domain = range(minpatients:maxpatients))
m07 <- leaflet() %>%
addTiles %>%
addPolygons(
data=stp_spdf,
group="ICS Tiles",
fillOpacity=1,
fillColor=~pal_metric2(stp_spdfdata1$NUMBER_OF_PATIENTS), #grey out the ICS tiles so there is less unnecessary detail
weight=0,
label=mytext_ics) %>%
addPolygons(
data=stp_spdf,
group="ICS boundary",
fillOpacity=0,
color='black',
weight=5,
label=mytext_ics) %>%
addMinicharts(lng = data_trust_spdf_pie$LONG,
lat = data_trust_spdf_pie$LAT,
type = "pie",
chartdata = data_trust_spdf_pie[, c("Standards_Exceeded", "Standards_Met", "Approaching_Standards", "Standards_Not_Met")],
colorPalette = c("#129F8C", '#9FD0BA', "#F5FFBF", "#FF4227"),
width = 25,
transitionTime = 0) %>%
addLegend("topright",pal=pal_metric2, minpatients:maxpatients, title="ICS Patient Population Level")
m07
##################
View(data_trust_spdf_pie)
#data_trust_spdf_pie = merge(x = data_trust_spdf_pie, y = stp_filter_numpatients, by = "STP21CD")
data_trust_spdf_pie[41, 7]
#data_trust_spdf_pie = merge(x = data_trust_spdf_pie, y = stp_filter_numpatients, by = "STP21CD")
data_trust_spdf_pie[41, 7] = 51.0
gppopdata_blue <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="ICB") %>% select(c("ONS_CODE","NUMBER_OF_PATIENTS"))
gppopdata_blue <- gppopdata_blue %>% rename("STP21CD" = 1)
stp_spdfdata <- stp_spdf@data
stp_spdfdata1 = merge(stp_spdfdata, gppopdata_blue, by = "STP21CD")
#stp_spdf$data <- stp_spdfdata1
num_patients_stp <- gppopdata_blue[c("NUMBER_OF_PATIENTS")]
minpatients <- min(num_patients_stp)
maxpatients <- max(num_patients_stp)
patients_stps <- stp_spdfdata$data.NUMBER_OF_PATIENTS
pal_metric2 <- colorNumeric(
palette = "Blues",
domain = range(minpatients:maxpatients))
m07 <- leaflet() %>%
addTiles %>%
addPolygons(
data=stp_spdf,
group="ICS Tiles",
fillOpacity=1,
fillColor=~pal_metric2(stp_spdfdata1$NUMBER_OF_PATIENTS), #grey out the ICS tiles so there is less unnecessary detail
weight=0,
label=mytext_ics) %>%
addPolygons(
data=stp_spdf,
group="ICS boundary",
fillOpacity=0,
color='black',
weight=5,
label=mytext_ics) %>%
addMinicharts(lng = data_trust_spdf_pie$LONG,
lat = data_trust_spdf_pie$LAT,
type = "pie",
chartdata = data_trust_spdf_pie[, c("Standards_Exceeded", "Standards_Met", "Approaching_Standards", "Standards_Not_Met")],
colorPalette = c("#129F8C", '#9FD0BA', "#F5FFBF", "#FF4227"),
width = 25,
transitionTime = 0) %>%
addLegend("topright",pal=pal_metric2, minpatients:maxpatients, title="ICS Patient Population Level")
m07
data_trust_spdf_pie[41, 6] = 0.0
gppopdata_blue <- gppopdata %>% filter(SEX=="ALL",AGE=="ALL",ORG_TYPE=="ICB") %>% select(c("ONS_CODE","NUMBER_OF_PATIENTS"))
gppopdata_blue <- gppopdata_blue %>% rename("STP21CD" = 1)
stp_spdfdata <- stp_spdf@data
stp_spdfdata1 = merge(stp_spdfdata, gppopdata_blue, by = "STP21CD")
#stp_spdf$data <- stp_spdfdata1
num_patients_stp <- gppopdata_blue[c("NUMBER_OF_PATIENTS")]
minpatients <- min(num_patients_stp)
maxpatients <- max(num_patients_stp)
patients_stps <- stp_spdfdata$data.NUMBER_OF_PATIENTS
pal_metric2 <- colorNumeric(
palette = "Blues",
domain = range(minpatients:maxpatients))
m07 <- leaflet() %>%
addTiles %>%
addPolygons(
data=stp_spdf,
group="ICS Tiles",
fillOpacity=1,
fillColor=~pal_metric2(stp_spdfdata1$NUMBER_OF_PATIENTS), #grey out the ICS tiles so there is less unnecessary detail
weight=0,
label=mytext_ics) %>%
addPolygons(
data=stp_spdf,
group="ICS boundary",
fillOpacity=0,
color='black',
weight=5,
label=mytext_ics) %>%
addMinicharts(lng = data_trust_spdf_pie$LONG,
lat = data_trust_spdf_pie$LAT,
type = "pie",
chartdata = data_trust_spdf_pie[, c("Standards_Exceeded", "Standards_Met", "Approaching_Standards", "Standards_Not_Met")],
colorPalette = c("#129F8C", '#9FD0BA', "#F5FFBF", "#FF4227"),
width = 25,
transitionTime = 0) %>%
addLegend("topright",pal=pal_metric2, minpatients:maxpatients, title="ICS Patient Population Level")
m07
#load in the snapshot data and filter for the 5 relevant CSUs
data_snapshot = read.csv('/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/data/DSPT search results 09_09_2022 12_44_07.csv')
data_summary = data_snapshot %>% select('Organisation.Name', 'Status', 'Primary.Sector')
data_summary = data_summary %>% filter(Primary.Sector == "Commissioning Support Unit (CSU)")
data_csu = data_summary %>% filter(str_detect(Organisation.Name, 'CSU'))
#get the joint dataframe of CCGs and Trusts and merge with CSUs
data_joint$Primary.Sector = data_joint$Sector
data_joint$Organisation.Name = data_joint$ODS.Org.Name
data_s = rbind(select(data_joint, 'Organisation.Name', 'Status', 'Primary.Sector'), data_csu)
#data_s = data_summary %>% mutate(Short.Status = case_when(Status %in% c("20/21 Standards Met", "18/19 Standards Met", "19/20 Standards Met", "19/20 Approaching Standards", "19/20 Standards Exceeded", "20/21 Standards Exceeded", "20/21 Standards Not Met") ~ '21/22 Status Not Met',
# Status %in% c("22/23 Standards Met") ~ '21/22 Standards Met', TRUE ~ Status))
auxl <-data_s %>% group_by(Primary.Sector,Status) %>% summarise(n=n())
aux <- data_s %>% group_by(Primary.Sector,Status) %>% summarise(n=n()) %>% pivot_wider(names_from='Status',values_from='n')
org_type <-aux$Primary.Sector
fig_x <- auxl %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')
fig_x
data_ccg = data_joing %>% filter(Sector == 'CCG')
data_ccg = data_join %>% filter(Sector == 'CCG')
data_ccg = data_joint %>% filter(Sector == 'CCG')
View(data_ccg)
tbl_summary(select(data_s, 'Primary.Sector', 'Status'), by = (c('Status')))
ct_final = ctable(data_s$Primary.Sector, data_s$Status,
prop = "r", chisq = FALSE, headings = FALSE
)
ct_final %>% print(method="browser")
ct_final %>% print(file=paste0("/Users/muhammad-faaiz.shanawas/Documents/GitHub/open-cyber/cross_table_summary_21_22",Sys.Date(),".html"))
aux <- data_s %>% group_by(Primary.Sector,Status) %>% summarise(n=n()) %>% pivot_wider(names_from='Status',values_from='n')
View(aux)
colnames(aux)
aux <- select(aux, "21/22 Standards Exceeded", "21/22 Standards Met", "21/22 Approaching Standards", "21/22 Standards Not Met")
org_type <-aux$Primary.Sector
fig_x <- auxl %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')
fig_x
View(auxl)
fig_x <- aux %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')
fig_x
fig_x <- aux %>% plot_ly(x=~Primary.Sector,y= ~n,type='bar')
fig_x
fig_x <- auxl %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')%>%
layout(xaxis = list(categoryorder = "category ascending"))
fig_x
fig_x <- auxl %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')%>%
layout(xaxis = list(categoryorder = "category descending"))
fig_x
xform <- list(categoryorder = "array",
categoryarray = c("21/22 Standards Exceeded", "21/22 Standards Met", "21/22 Approaching Standards", "21/22 Standards Not Met"))
fig_x <- auxl %>% plot_ly(x=~Primary.Sector,y= ~n,color=~Status,type='bar')%>%
layout(xaxis = xform)
fig_x
org_type <-aux$Primary.Sector