Skip to content

Commit 350721d

Browse files
committed
guide_axis_theta: fix missing label for one unique key
1 parent 63ca94e commit 350721d

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

R/guide-axis-theta.R

Lines changed: 3 additions & 2 deletions
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),
Lines changed: 52 additions & 0 deletions
Loading

tests/testthat/test-guide-axis.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ 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 value", {
386+
p <- ggplot(data.frame(x = "a", y = 1:3), aes(x, y)) +
387+
geom_point() +
388+
coord_radial(start = 0, end = pi / 2, inner.radius = 0.5) +
389+
guides(theta = guide_axis_theta(angle = 0))
390+
expect_doppelganger("guide_axis_theta with only one axis value", p)
391+
})
392+
385393
test_that("guide_axis_theta can be used in cartesian coordinates", {
386394

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

0 commit comments

Comments
 (0)