Skip to content

Commit 1ae5a90

Browse files
authored
guide_axis_theta: fix missing label for one unique key (#6424)
* guide_axis_theta: fix missing label for one unique key * rename the test result * simplify the test
1 parent 63ca94e commit 1ae5a90

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

R/guide-axis-theta.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ GuideAxisTheta <- ggproto(
104104

105105
# If the first and last positions are close together, we merge the
106106
# labels of these positions
107-
ends_apart <- (key$theta[n] - key$theta[1]) %% (2 * pi)
108-
if (n > 0 && ends_apart < 0.05 && !is.null(key$.label)) {
107+
if (n > 1L &&
108+
(key$theta[n] - key$theta[1]) %% (2 * pi) < 0.05 &&
109+
!is.null(key$.label)) {
109110
if (is.expression(key$.label[[1]])) {
110111
combined <- substitute(
111112
paste(a, "/", b),

tests/testthat/test-guide-axis.R

+7
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ test_that("guide_axis_theta sets relative angle", {
382382
expect_doppelganger("guide_axis_theta with angle adapting to theta", p)
383383
})
384384

385+
test_that("guide_axis_theta with only one axis key", {
386+
p <- ggplot(data.frame(x = "a", y = 1:3), aes(x, y)) +
387+
geom_point() +
388+
coord_radial()
389+
expect_identical(get_guide_data(p, "theta")$.label, "a")
390+
})
391+
385392
test_that("guide_axis_theta can be used in cartesian coordinates", {
386393

387394
p <- ggplot(mtcars, aes(disp, mpg)) +

0 commit comments

Comments
 (0)