Skip to content

Commit d06fa35

Browse files
committed
add test
1 parent dfcba72 commit d06fa35

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

R/guide-bins.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ GuideBins <- ggproto(
210210
if (params$reverse) {
211211
ord <- seq_len(nrow(key))
212212
key <- vec_slice(key, rev(ord))
213+
# Put NA back in the trailing position
213214
key[params$aesthetic] <- vec_slice(key[params$aesthetic], c(ord[-1], ord[1]))
214215
key$.value <- 1 - key$.value
215216
}
Lines changed: 97 additions & 0 deletions
Loading

tests/testthat/test-guides.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,22 @@ test_that("guides title and text are positioned correctly", {
378378
expect_doppelganger("legends with all title justifications", p)
379379
})
380380

381+
test_that("bin guide can be reversed", {
382+
383+
p <- ggplot(data.frame(x = c(0, 100)), aes(x, x, colour = x, fill = x)) +
384+
geom_point() +
385+
guides(
386+
colour = guide_bins(reverse = TRUE, show.limits = TRUE, order = 1),
387+
fill = guide_bins(
388+
reverse = TRUE, show.limits = FALSE, order = 2,
389+
override.aes = list(shape = 21)
390+
)
391+
)
392+
393+
expect_doppelganger("reversed guide_bins", p)
394+
395+
})
396+
381397
test_that("bin guide can be styled correctly", {
382398
df <- data_frame(x = c(1, 2, 3),
383399
y = c(6, 5, 7))

0 commit comments

Comments
 (0)