Skip to content

Commit ebb6ecd

Browse files
committed
Optionally enable customisation of the penalty arc
The true radius should be 10 yards, not 12 (penalty distance). However this can look weird on some dimensions. Enabling customisation allows users to circumvent this. Dimensions which can support the true radius have been amended. See #35 Closes #35
1 parent 282c1b1 commit ebb6ecd

12 files changed

+70
-8
lines changed

R/dimensions.R

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#' \item{"goal_width"}{The distance from one goal post to the other}
2222
#' \item{"origin_x"}{The minimum x coordinate of the pitch}
2323
#' \item{"origin_y"}{The minimum y coordinate of the pitch}
24+
#' \item{"penalty_arc_radius"}{The radius of the arc above the penalty box (Optional). Defaults to `penalty_spot_distance`}
2425
#' }
2526
#'
2627
#' The following pitch dimensions are provided
@@ -75,7 +76,8 @@ pitch_statsbomb <- list(
7576
penalty_spot_distance = 12,
7677
goal_width = 8,
7778
origin_x = 0,
78-
origin_y = 0
79+
origin_y = 0,
80+
penalty_arc_radius = 10
7981
)
8082

8183
#' @rdname pitch_opta
@@ -98,6 +100,7 @@ pitch_wyscout <- list(
98100
#' @export
99101
# As per UEFA Category 4 regulations
100102
# Source: https://en.wikipedia.org/wiki/UEFA_stadium_categories
103+
# Source: https://en.wikipedia.org/wiki/Penalty_area
101104
pitch_international <- list(
102105
length = 105,
103106
width = 68,
@@ -108,7 +111,8 @@ pitch_international <- list(
108111
penalty_spot_distance = 11,
109112
goal_width = 7.32,
110113
origin_x = 0,
111-
origin_y = 0
114+
origin_y = 0,
115+
penalty_arc_radius = 9.15
112116
)
113117

114118

@@ -152,7 +156,7 @@ make_pitch_tracab <- function(length=105, width=68){
152156
#' @export
153157
pitch_tracab <- make_pitch_tracab()
154158

155-
159+
156160
#' @rdname pitch_opta
157161
#' @export
158162
# Source: https://glossary.impect.com/api-design?tab=2
@@ -166,5 +170,6 @@ pitch_impect <- list(
166170
penalty_spot_distance = 11,
167171
goal_width = 7.32,
168172
origin_x = -52.5,
169-
origin_y = -34
173+
origin_y = -34,
174+
penalty_arc_radius = 10
170175
)
-27 Bytes
Loading
32 Bytes
Loading
Loading
16 Bytes
Loading
28 Bytes
Loading
21 Bytes
Loading
2 Bytes
Loading
15 Bytes
Loading
-6 Bytes
Loading

man/pitch_opta.Rd

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-dimensions-plot-without-error.R

+56
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,62 @@ test_that("Plotting valid pitch dimensions with a negative origin plots without
7979
})
8080

8181

82+
test_that("Plotting dimensions without a `penalty_arc_radius` doesn't error", {
83+
dim <- list(
84+
length = 100,
85+
width = 100,
86+
penalty_box_length = 17,
87+
penalty_box_width = 57.8,
88+
six_yard_box_length = 5.8,
89+
six_yard_box_width = 26.4,
90+
penalty_spot_distance = 11.5,
91+
goal_width = 11.6,
92+
origin_x = 0,
93+
origin_y = 0
94+
)
95+
96+
expect_no_error({
97+
ggplot2::ggplot() +
98+
annotate_pitch(dimensions = dim)
99+
})
100+
101+
# Also check for warnings
102+
expect_no_warning({
103+
ggplot2::ggplot() +
104+
annotate_pitch(dimensions = dim)
105+
})
106+
})
107+
108+
109+
test_that("Plotting dimensions with a `penalty_arc_radius` doesn't error", {
110+
dim <- list(
111+
length = 100,
112+
width = 100,
113+
penalty_box_length = 17,
114+
penalty_box_width = 57.8,
115+
six_yard_box_length = 5.8,
116+
six_yard_box_width = 26.4,
117+
penalty_spot_distance = 11.5,
118+
goal_width = 11.6,
119+
origin_x = 0,
120+
origin_y = 0,
121+
penalty_arc_radius = 10
122+
)
123+
124+
expect_no_error({
125+
ggplot2::ggplot() +
126+
annotate_pitch(dimensions = dim)
127+
})
128+
129+
# Also check for warnings
130+
# arcs
131+
expect_no_warning({
132+
ggplot2::ggplot() +
133+
annotate_pitch(dimensions = dim)
134+
})
135+
})
136+
137+
82138

83139

84140

0 commit comments

Comments
 (0)