Skip to content

Commit df6d1af

Browse files
committed
added max.overlaps argument
1 parent 8f92868 commit df6d1af

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

R/draw_plot.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

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

3535
# Bind variable for NSE
3636
numerator <- denominator <- number.seq <- ll95 <- ul95 <- ll998 <- ul998 <- odll95 <- odul95 <-
@@ -149,7 +149,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
149149
geom_label_repel(aes(label = ifelse(highlight == 1,
150150
as.character(group), NA))
151151
, size=2.5, point.padding=0, direction = "both", force = 2
152-
, min.segment.length=0, na.rm=TRUE)
152+
, min.segment.length=0, na.rm=TRUE, max.overlaps = max.overlaps)
153153
}
154154

155155
if(draw_adjusted == FALSE & draw_unadjusted == FALSE){
@@ -164,7 +164,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
164164
geom_label_repel(aes(label = ifelse(outlier == 1,
165165
as.character(group), NA))
166166
, size=2.5, point.padding=0, direction = "both", force = 2
167-
, min.segment.length=0, na.rm=TRUE)
167+
, min.segment.length=0, na.rm=TRUE, max.overlaps = max.overlaps)
168168
}
169169

170170
if(label=="outlier_lower"){
@@ -173,7 +173,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
173173
geom_label_repel(aes(label = ifelse(outlier == 1 & rr < 1,
174174
as.character(group), NA))
175175
, size=2.5,point.padding=0, direction = "both", force = 2
176-
, min.segment.length=0, na.rm=TRUE)
176+
, min.segment.length=, na.rm=TRUE, max.overlaps = max.overlaps)
177177
}
178178

179179
if(label=="outlier_upper"){
@@ -182,7 +182,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
182182
geom_label_repel(aes(label = ifelse(outlier == 1 & rr > 1,
183183
as.character(group), NA))
184184
, size=2.5, point.padding=0, direction = "both", force = 2
185-
, min.segment.length=0, na.rm=TRUE)
185+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
186186
}
187187

188188

@@ -191,7 +191,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
191191
geom_label_repel(aes(label = ifelse((highlight == 1 | outlier == 1) ,
192192
as.character(group), NA))
193193
, size=2.5, point.padding=0, direction = "both", force = 2
194-
, min.segment.length=0, na.rm=TRUE)
194+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
195195

196196
}
197197

@@ -200,7 +200,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
200200
geom_label_repel(aes(label = ifelse((highlight == 1 | (outlier == 1& rr < 1)) ,
201201
as.character(group), NA))
202202
, size=2.5, point.padding=0, direction = "both", force = 2
203-
, min.segment.length=0, na.rm=TRUE)
203+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
204204

205205
}
206206

@@ -209,7 +209,7 @@ draw_plot<-function(mod_plot_agg, limits, x_label, y_label, title, label, multip
209209
geom_label_repel(aes(label = ifelse((highlight == 1 | (outlier == 1 & rr > 1)) ,
210210
as.character(group), NA))
211211
, size=2.5, point.padding=0, direction = "both", force = 2
212-
, min.segment.length=0, na.rm=TRUE)
212+
, min.segment.length=1, na.rm=TRUE, max.overlaps = max.overlaps)
213213

214214
}
215215
}

R/funnel_plot.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#' Default has been chosen to avoid red and green which can lead to subconscious value judgements of good or bad.
4949
#' Default is hex colours: c("#FF7F0EFF", "#FF7F0EFF", "#1F77B4FF","#1F77B4FF", "#9467BDFF", "#9467BDFF", "#2CA02CFF", "#2CA02CFF")
5050
#' @param SHMI_rounding TRUE/FALSE, for SHMI calculation (standardised ratio, with SHMI truncation etc.), should you round the expected values to 2 decimal places (TRUE) or not (FALSE)
51+
#' @param max.overlaps Exclude text labels that overlap too many things. Defaults to 10. (inheritted from geom_label_repel)
5152
#'
5253
#'
5354
#' @return A fitted `funnelplot` object. A `funnelplot` object is a list containing the following components:\cr
@@ -127,7 +128,8 @@ funnel_plot <- function(.data, numerator, denominator, group
127128
, theme = funnel_clean()
128129
, label_outliers, Poisson_limits, OD_adjust
129130
, xrange, yrange
130-
, SHMI_rounding = TRUE){
131+
, SHMI_rounding = TRUE
132+
, max.overlaps = 10){
131133

132134
# Version 0.4 deprecation warnings
133135
if (!missing(label_outliers)) {
@@ -380,7 +382,7 @@ funnel_plot <- function(.data, numerator, denominator, group
380382
multiplier=multiplier,
381383
draw_unadjusted=draw_unadjusted, draw_adjusted=draw_adjusted,
382384
target=target, min_y, max_y, min_x, max_x, data_type=data_type,
383-
sr_method = sr_method, theme = theme, plot_cols=plot_cols)
385+
sr_method = sr_method, theme = theme, plot_cols=plot_cols, max.overlaps = max.overlaps)
384386

385387

386388
# Subset outliers for reporting

man/draw_plot.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/funnel_plot.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)