Skip to content

Commit bcc9426

Browse files
committed
bring up to date from main
Merge branch 'main' into renamelegend # Conflicts: # R/funnel_plot.R
2 parents 9a78b71 + 3ebcb92 commit bcc9426

25 files changed

Lines changed: 423 additions & 239 deletions

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ NHSEI_AHSN_limits.R
1616
^dev$
1717
^codecov\.yml$
1818
^\.github$
19+
test_func.R

.github/workflows/rhub.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
2+
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
3+
# You can update this file to a newer version using the rhub2 package:
4+
#
5+
# rhub::rhub_setup()
6+
#
7+
# It is unlikely that you need to modify this file manually.
8+
9+
name: R-hub
10+
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
config:
16+
description: 'A comma separated list of R-hub platforms to use.'
17+
type: string
18+
default: 'linux,windows,macos'
19+
name:
20+
description: 'Run name. You can leave this empty now.'
21+
type: string
22+
id:
23+
description: 'Unique ID. You can leave this empty now.'
24+
type: string
25+
26+
jobs:
27+
28+
setup:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
containers: ${{ steps.rhub-setup.outputs.containers }}
32+
platforms: ${{ steps.rhub-setup.outputs.platforms }}
33+
34+
steps:
35+
# NO NEED TO CHECKOUT HERE
36+
- uses: r-hub/actions/setup@v1
37+
with:
38+
config: ${{ github.event.inputs.config }}
39+
id: rhub-setup
40+
41+
linux-containers:
42+
needs: setup
43+
if: ${{ needs.setup.outputs.containers != '[]' }}
44+
runs-on: ubuntu-latest
45+
name: ${{ matrix.config.label }}
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
config: ${{ fromJson(needs.setup.outputs.containers) }}
50+
container:
51+
image: ${{ matrix.config.container }}
52+
53+
steps:
54+
- uses: r-hub/actions/checkout@v1
55+
- uses: r-hub/actions/platform-info@v1
56+
with:
57+
token: ${{ secrets.RHUB_TOKEN }}
58+
job-config: ${{ matrix.config.job-config }}
59+
- uses: r-hub/actions/setup-deps@v1
60+
with:
61+
token: ${{ secrets.RHUB_TOKEN }}
62+
job-config: ${{ matrix.config.job-config }}
63+
- uses: r-hub/actions/run-check@v1
64+
with:
65+
token: ${{ secrets.RHUB_TOKEN }}
66+
job-config: ${{ matrix.config.job-config }}
67+
68+
other-platforms:
69+
needs: setup
70+
if: ${{ needs.setup.outputs.platforms != '[]' }}
71+
runs-on: ${{ matrix.config.os }}
72+
name: ${{ matrix.config.label }}
73+
strategy:
74+
fail-fast: false
75+
matrix:
76+
config: ${{ fromJson(needs.setup.outputs.platforms) }}
77+
78+
steps:
79+
- uses: r-hub/actions/checkout@v1
80+
- uses: r-hub/actions/setup-r@v1
81+
with:
82+
job-config: ${{ matrix.config.job-config }}
83+
token: ${{ secrets.RHUB_TOKEN }}
84+
- uses: r-hub/actions/platform-info@v1
85+
with:
86+
token: ${{ secrets.RHUB_TOKEN }}
87+
job-config: ${{ matrix.config.job-config }}
88+
- uses: r-hub/actions/setup-deps@v1
89+
with:
90+
job-config: ${{ matrix.config.job-config }}
91+
token: ${{ secrets.RHUB_TOKEN }}
92+
- uses: r-hub/actions/run-check@v1
93+
with:
94+
job-config: ${{ matrix.config.job-config }}
95+
token: ${{ secrets.RHUB_TOKEN }}

DESCRIPTION

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: FunnelPlotR
22
Type: Package
33
Title: Funnel Plots for Comparing Institutional Performance
4-
Version: 0.4.9999
4+
Version: 0.5.0
55
Authors@R: c(
66
person("Chris", "Mainey", ,"c.mainey1@nhs.net", role= c("aut", "cre"),
77
comment = c(ORCID ="0000-0002-3018-6171")
@@ -18,18 +18,19 @@ License: MIT + file LICENSE
1818
URL: https://nhs-r-community.github.io/FunnelPlotR/, https://github.com/nhs-r-community/FunnelPlotR
1919
BugReports: https://github.com/nhs-r-community/FunnelPlotR/issues
2020
Encoding: UTF-8
21-
Imports: dplyr,
22-
ggrepel,
23-
ggplot2,
24-
scales
25-
RoxygenNote: 7.2.3
21+
Imports:
22+
dplyr,
23+
ggrepel,
24+
ggplot2,
25+
scales,
26+
rlang
27+
RoxygenNote: 7.3.1
2628
Suggests:
2729
testthat (>= 3.0.0),
2830
knitr,
2931
rmarkdown,
3032
COUNT,
3133
tidyr,
32-
covr,
33-
Cairo
34+
covr
3435
VignetteBuilder: knitr
3536
Config/testthat/edition: 3

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ importFrom(ggplot2,theme_grey)
3232
importFrom(ggplot2,theme_minimal)
3333
importFrom(ggrepel,geom_label_repel)
3434
importFrom(ggrepel,geom_text_repel)
35+
importFrom(rlang,.data)
3536
importFrom(scales,comma)
3637
importFrom(stats,aggregate)
3738
importFrom(stats,na.omit)

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# FunnelPlotR 0.5.0
2+
3+
- Breaking change
4+
* Tidyeval approach added, with function now taking the data argument first, allowing piping, and allows unquoted column names to fit with tidyverse / dplyr style approach.
5+
6+
- Changes
7+
* Added a `max.overlaps` argument to allow the user to vary this in cases where labels overlap is unhelpful.
8+
* Changed control limit options to allow both adjusted and unadjusted to be turned off, without turning the other on.
9+
* Updated README, help files and vignette to use tidyeval approach.
10+
11+
12+
113
# FunnelPlotR 0.4.2
214
- Changes:
315
* Handling of expected values in SHMI calculation was adjusted to allow rounding to two decimal places to match NHSD publication, and as requested by HED Team. Now controlled with additional argument: `SHMI_rounding` = TRUE/FALSE

R/build_limits_lookup.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#' Function to build funnel limits
22
#' @description Internal function for funnel plot to build the control limits prior to plotting.
3-
#' @param min_preds Minimum predicted value for range of x-axis
4-
#' @param max_preds Maximum predicted value for range of x-axis
5-
#' @param min_ratio Minimum ratio value for range of y-axis
6-
#' @param max_ratio Maximum ratio value for range of y-axis
7-
#' @param draw_unadjusted TRUE/FALSE Draw Poisson distribution limits?
3+
#' @param min_x Minimum predicted value for range of x-axis
4+
#' @param max_x Maximum predicted value for range of x-axis
5+
#' @param min_y Minimum ratio value for range of y-axis
6+
#' @param max_y Maximum ratio value for range of y-axis
87
#' @param draw_adjusted TRUE/FALSE Use overdispersion adjustment
98
#' @param tau2 If using draw_adjusted, what is the tau2 ("between" standard error) to use?
109
#' @param data_type SR, PR or RC. Used to set target reference
@@ -18,12 +17,12 @@
1817
build_limits_lookup<-function(min_x, max_x, min_y, max_y
1918
, draw_adjusted, tau2, data_type, sr_method
2019
, target, multiplier, denominators){
21-
22-
20+
21+
2322
# general limits + tau2 limits table
2423
set.seed(1)
2524

26-
25+
2726
if(data_type=="SR"){
2827
number.seq <- seq(1.1, as.numeric(max_x), length.out = 1000)
2928
} else {

R/draw_plot.R

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multiplier,
3333
draw_unadjusted, draw_adjusted, target, min_y, max_y, min_x, max_x
34-
, data_type, sr_method, theme, plot_cols){
34+
, data_type, sr_method, theme, plot_cols, max.overlaps){
3535

3636
# Bind variable for NSE
3737
numerator <- denominator <- number.seq <- ll95 <- ul95 <- ll998 <- ul998 <- odll95 <- odul95 <-
@@ -114,6 +114,9 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
114114
angle = 0
115115
), override.aes = list(linetype = c(2,1)) ))
116116
}
117+
if (draw_unadjusted == FALSE & draw_adjusted == FALSE){
118+
funnel_p
119+
}
117120
}
118121

119122
# Apply plot scaling
@@ -129,17 +132,32 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
129132

130133

131134

132-
135+
133136

134137
# Label points
135138
if(!is.na(label)){
139+
140+
if(label=="highlight"){
141+
funnel_p <- funnel_p +
142+
geom_label_repel(aes(label = ifelse(highlight == 1,
143+
as.character(group), NA))
144+
, size=2.5, point.padding=0, direction = "both", force = 2
145+
, min.segment.length=0, na.rm=TRUE, max.overlaps = max.overlaps)
146+
}
147+
148+
if(draw_adjusted == FALSE & draw_unadjusted == FALSE){
149+
funnel_p
150+
}
151+
152+
153+
136154
if(label=="outlier"){
137155

138156
funnel_p <- funnel_p +
139157
geom_label_repel(aes(label = ifelse(outlier == 1,
140158
as.character(group), NA))
141159
, size=2.5, point.padding=0, direction = "both", force = 2
142-
, min.segment.length=0, na.rm=TRUE)
160+
, min.segment.length=0, na.rm=TRUE, max.overlaps = max.overlaps)
143161
}
144162

145163
if(label=="outlier_lower"){
@@ -148,7 +166,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
148166
geom_label_repel(aes(label = ifelse(outlier == 1 & rr < 1,
149167
as.character(group), NA))
150168
, size=2.5,point.padding=0, direction = "both", force = 2
151-
, min.segment.length=0, na.rm=TRUE)
169+
, min.segment.length=, na.rm=TRUE, max.overlaps = max.overlaps)
152170
}
153171

154172
if(label=="outlier_upper"){
@@ -157,23 +175,16 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
157175
geom_label_repel(aes(label = ifelse(outlier == 1 & rr > 1,
158176
as.character(group), NA))
159177
, size=2.5, point.padding=0, direction = "both", force = 2
160-
, min.segment.length=0, na.rm=TRUE)
161-
}
162-
163-
if(label=="highlight"){
164-
funnel_p <- funnel_p +
165-
geom_label_repel(aes(label = ifelse(highlight == 1,
166-
as.character(group), NA))
167-
, size=2.5, point.padding=0, direction = "both", force = 2
168-
, min.segment.length=0, na.rm=TRUE)
178+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
169179
}
170180

181+
171182
if(label=="both"){
172183
funnel_p <- funnel_p +
173184
geom_label_repel(aes(label = ifelse((highlight == 1 | outlier == 1) ,
174185
as.character(group), NA))
175186
, size=2.5, point.padding=0, direction = "both", force = 2
176-
, min.segment.length=0, na.rm=TRUE)
187+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
177188

178189
}
179190

@@ -182,7 +193,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
182193
geom_label_repel(aes(label = ifelse((highlight == 1 | (outlier == 1& rr < 1)) ,
183194
as.character(group), NA))
184195
, size=2.5, point.padding=0, direction = "both", force = 2
185-
, min.segment.length=0, na.rm=TRUE)
196+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
186197

187198
}
188199

@@ -191,7 +202,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
191202
geom_label_repel(aes(label = ifelse((highlight == 1 | (outlier == 1 & rr > 1)) ,
192203
as.character(group), NA))
193204
, size=2.5, point.padding=0, direction = "both", force = 2
194-
, min.segment.length=0, na.rm=TRUE)
205+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
195206

196207
}
197208
}

0 commit comments

Comments
 (0)