diff --git a/R/guide-axis-theta.R b/R/guide-axis-theta.R index af96a337b6..5183e802fc 100644 --- a/R/guide-axis-theta.R +++ b/R/guide-axis-theta.R @@ -104,8 +104,9 @@ GuideAxisTheta <- ggproto( # If the first and last positions are close together, we merge the # labels of these positions - ends_apart <- (key$theta[n] - key$theta[1]) %% (2 * pi) - if (n > 0 && ends_apart < 0.05 && !is.null(key$.label)) { + if (n > 1L && + (key$theta[n] - key$theta[1]) %% (2 * pi) < 0.05 && + !is.null(key$.label)) { if (is.expression(key$.label[[1]])) { combined <- substitute( paste(a, "/", b), diff --git a/tests/testthat/test-guide-axis.R b/tests/testthat/test-guide-axis.R index 5e2010d1c5..85e1477024 100644 --- a/tests/testthat/test-guide-axis.R +++ b/tests/testthat/test-guide-axis.R @@ -382,6 +382,13 @@ test_that("guide_axis_theta sets relative angle", { expect_doppelganger("guide_axis_theta with angle adapting to theta", p) }) +test_that("guide_axis_theta with only one axis key", { + p <- ggplot(data.frame(x = "a", y = 1:3), aes(x, y)) + + geom_point() + + coord_radial() + expect_identical(get_guide_data(p, "theta")$.label, "a") +}) + test_that("guide_axis_theta can be used in cartesian coordinates", { p <- ggplot(mtcars, aes(disp, mpg)) +