Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions R/guide-axis-theta.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions tests/testthat/test-guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ 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(start = 0, end = pi / 2, inner.radius = 0.5) +
guides(theta = guide_axis_theta(angle = 0))
expect_doppelganger("guide_axis_theta with only one axis key", p)
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this needs a visual snapshot, we can get_guide_data(p, "theta") to test the representation of the guide. The rest of the plot can also be simplified by leaving out the guides() and the arguments to coord_radial().

test_that("guide_axis_theta can be used in cartesian coordinates", {

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