Skip to content

Commit 7378156

Browse files
authored
Radial inner radius (#5679)
* rename `donut` -> `inner.radius` * regenerate docs
1 parent fa6d68d commit 7378156

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

R/coord-radial.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@
1515
#' in accordance with the computed `theta` position. If `FALSE` (default),
1616
#' no such transformation is performed. Can be useful to rotate text geoms in
1717
#' alignment with the coordinates.
18-
#' @param donut A `numeric` between 0 and 1 setting the size of a donut hole.
18+
#' @param inner.radius A `numeric` between 0 and 1 setting the size of a inner.radius hole.
1919
#'
2020
#' @note
2121
#' In `coord_radial()`, position guides are can be defined by using
2222
#' `guides(r = ..., theta = ..., r.sec = ..., theta.sec = ...)`. Note that
2323
#' these guides require `r` and `theta` as available aesthetics. The classic
2424
#' `guide_axis()` can be used for the `r` positions and `guide_axis_theta()` can
2525
#' be used for the `theta` positions. Using the `theta.sec` position is only
26-
#' sensible when `donut > 0`.
26+
#' sensible when `inner.radius > 0`.
2727
#'
2828
#' @export
2929
#' @examples
3030
#' # A partial polar plot
3131
#' ggplot(mtcars, aes(disp, mpg)) +
3232
#' geom_point() +
33-
#' coord_radial(start = -0.4 * pi, end = 0.4 * pi, donut = 0.3)
33+
#' coord_radial(start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3)
3434
coord_radial <- function(theta = "x",
3535
start = 0, end = NULL,
3636
expand = TRUE,
3737
direction = 1,
3838
clip = "off",
3939
r_axis_inside = NULL,
4040
rotate_angle = FALSE,
41-
donut = 0) {
41+
inner.radius = 0) {
4242

4343
theta <- arg_match0(theta, c("x", "y"))
4444
r <- if (theta == "x") "y" else "x"
@@ -47,7 +47,7 @@ coord_radial <- function(theta = "x",
4747
check_bool(rotate_angle)
4848
check_number_decimal(start, allow_infinite = FALSE)
4949
check_number_decimal(end, allow_infinite = FALSE, allow_null = TRUE)
50-
check_number_decimal(donut, min = 0, max = 1, allow_infinite = FALSE)
50+
check_number_decimal(inner.radius, min = 0, max = 1, allow_infinite = FALSE)
5151

5252
end <- end %||% (start + 2 * pi)
5353
if (start > end) {
@@ -64,7 +64,7 @@ coord_radial <- function(theta = "x",
6464
direction = sign(direction),
6565
r_axis_inside = r_axis_inside,
6666
rotate_angle = rotate_angle,
67-
donut = c(donut, 1) * 0.4,
67+
inner_radius = c(inner.radius, 1) * 0.4,
6868
clip = clip
6969
)
7070
}
@@ -84,13 +84,13 @@ CoordRadial <- ggproto("CoordRadial", Coord,
8484
distance = function(self, x, y, details) {
8585
arc <- details$arc %||% c(0, 2 * pi)
8686
if (self$theta == "x") {
87-
r <- rescale(y, from = details$r.range, to = self$donut / 0.4)
87+
r <- rescale(y, from = details$r.range, to = self$inner_radius / 0.4)
8888
theta <- theta_rescale_no_clip(
8989
x, details$theta.range,
9090
arc, self$direction
9191
)
9292
} else {
93-
r <- rescale(x, from = details$r.range, to = self$donut / 0.4)
93+
r <- rescale(x, from = details$r.range, to = self$inner_radius / 0.4)
9494
theta <- theta_rescale_no_clip(
9595
y, details$theta.range,
9696
arc, self$direction
@@ -117,8 +117,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
117117
c(
118118
view_scales_polar(scale_x, self$theta, expand = self$expand),
119119
view_scales_polar(scale_y, self$theta, expand = self$expand),
120-
list(bbox = polar_bbox(self$arc, donut = self$donut),
121-
arc = self$arc, donut = self$donut)
120+
list(bbox = polar_bbox(self$arc, inner_radius = self$inner_radius),
121+
arc = self$arc, inner_radius = self$inner_radius)
122122
)
123123
},
124124

@@ -224,7 +224,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
224224
bbox <- panel_params$bbox %||% list(x = c(0, 1), y = c(0, 1))
225225
arc <- panel_params$arc %||% c(0, 2 * pi)
226226

227-
data$r <- r_rescale(data$r, panel_params$r.range, panel_params$donut)
227+
data$r <- r_rescale(data$r, panel_params$r.range, panel_params$inner_radius)
228228
data$theta <- theta_rescale(
229229
data$theta, panel_params$theta.range,
230230
arc, self$direction
@@ -258,7 +258,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
258258
bbox <- panel_params$bbox %||% list(x = c(0, 1), y = c(0, 1))
259259
arc <- panel_params$arc %||% c(0, 2 * pi)
260260
dir <- self$direction
261-
donut <- panel_params$donut
261+
inner_radius <- panel_params$inner_radius
262262

263263
theta_lim <- panel_params$theta.range
264264
theta_maj <- panel_params$theta.major
@@ -273,7 +273,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
273273
theta_fine <- seq(self$arc[1], self$arc[2], length.out = 100)
274274

275275
r_fine <- r_rescale(panel_params$r.major, panel_params$r.range,
276-
panel_params$donut)
276+
panel_params$inner_radius)
277277

278278
# This gets the proper theme element for theta and r grid lines:
279279
# panel.grid.major.x or .y
@@ -308,8 +308,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
308308

309309
ggname("grill", grobTree(
310310
background,
311-
theta_grid(theta_maj, grid_elems[[1]], donut, bbox),
312-
theta_grid(theta_min, grid_elems[[2]], donut, bbox),
311+
theta_grid(theta_maj, grid_elems[[1]], inner_radius, bbox),
312+
theta_grid(theta_min, grid_elems[[2]], inner_radius, bbox),
313313
element_render(
314314
theme, majorr, name = "radius",
315315
x = rescale(rep(r_fine, each = length(theta_fine)) *
@@ -453,7 +453,7 @@ view_scales_polar <- function(scale, theta = "x", expand = TRUE) {
453453
#' @examples
454454
#' polar_bbox(c(0, 1) * pi)
455455
polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
456-
donut = c(0, 0.4)) {
456+
inner_radius = c(0, 0.4)) {
457457

458458
# Early exit if we have full circle or more
459459
if (abs(diff(arc)) >= 2 * pi) {
@@ -463,8 +463,8 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
463463
# X and Y position of the sector arc ends
464464
xmax <- 0.5 * sin(arc) + 0.5
465465
ymax <- 0.5 * cos(arc) + 0.5
466-
xmin <- donut[1] * sin(arc) + 0.5
467-
ymin <- donut[1] * cos(arc) + 0.5
466+
xmin <- inner_radius[1] * sin(arc) + 0.5
467+
ymin <- inner_radius[1] * cos(arc) + 0.5
468468

469469
margin <- c(
470470
max(ymin) + margin[1],
@@ -546,16 +546,16 @@ flip_data_text_angle <- function(data) {
546546
}
547547

548548

549-
theta_grid <- function(theta, element, donut = c(0, 0.4),
549+
theta_grid <- function(theta, element, inner_radius = c(0, 0.4),
550550
bbox = list(x = c(0, 1), y = c(0, 1))) {
551551
n <- length(theta)
552552
if (n < 1) {
553553
return(NULL)
554554
}
555555

556-
donut <- rep(donut, n)
557-
x <- rep(sin(theta), each = 2) * donut + 0.5
558-
y <- rep(cos(theta), each = 2) * donut + 0.5
556+
inner_radius <- rep(inner_radius, n)
557+
x <- rep(sin(theta), each = 2) * inner_radius + 0.5
558+
y <- rep(cos(theta), each = 2) * inner_radius + 0.5
559559

560560
element_grob(
561561
element,

man/coord_polar.Rd

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

tests/testthat/_snaps/coord-polar/donut-with-all-axes.svg renamed to tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/testthat/test-coord-polar.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ test_that("bounding box calculations are sensible", {
136136
list(x = c(0.45, 1), y = c(0.146446609, 0.853553391))
137137
)
138138

139-
# Top quarter of circle with donuthole
139+
# Top quarter of circle with inner radius
140140
expect_equal(
141-
polar_bbox(arc = c(-0.25 * pi, 0.25 * pi), donut = c(0.2, 0.4)),
141+
polar_bbox(arc = c(-0.25 * pi, 0.25 * pi), inner_radius = c(0.2, 0.4)),
142142
list(x = c(0.146446609, 0.853553391), y = c(0.59142136, 1))
143143
)
144144
})
@@ -219,13 +219,13 @@ test_that("coord_radial() draws correctly", {
219219
geom_point() +
220220
theme
221221

222-
expect_doppelganger("donut with all axes", {
223-
p + coord_radial(donut = 0.3, r_axis_inside = FALSE) +
222+
expect_doppelganger("inner.radius with all axes", {
223+
p + coord_radial(inner.radius = 0.3, r_axis_inside = FALSE) +
224224
guides(r.sec = "axis", theta.sec = "axis_theta")
225225
})
226226

227227
expect_doppelganger("partial with all axes", {
228-
p + coord_radial(start = 0.25 * pi, end = 0.75 * pi, donut = 0.3,
228+
p + coord_radial(start = 0.25 * pi, end = 0.75 * pi, inner.radius = 0.3,
229229
r_axis_inside = TRUE, theta = "y") +
230230
guides(r.sec = "axis", theta.sec = "axis_theta")
231231
})

tests/testthat/test-guides.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ test_that("guide_axis_stack stacks axes", {
725725
p <- ggplot(mtcars, aes(hp, disp)) +
726726
geom_point() +
727727
theme(axis.line = element_line()) +
728-
coord_radial(start = 0.25 * pi, end = 1.75 * pi, donut = 0.5) +
728+
coord_radial(start = 0.25 * pi, end = 1.75 * pi, inner.radius = 0.5) +
729729
guides(theta = top, theta.sec = bottom, r = left, r.sec = right)
730730
expect_doppelganger("stacked radial axes", p)
731731

@@ -1110,7 +1110,7 @@ test_that("guide_axis_theta sets relative angle", {
11101110
p <- ggplot(mtcars, aes(disp, mpg)) +
11111111
geom_point() +
11121112
scale_x_continuous(breaks = breaks_width(25)) +
1113-
coord_radial(donut = 0.5) +
1113+
coord_radial(inner.radius = 0.5) +
11141114
guides(
11151115
theta = guide_axis_theta(angle = 0, cap = "none"),
11161116
theta.sec = guide_axis_theta(angle = 90, cap = "both")

0 commit comments

Comments
 (0)