Skip to content

Commit a62895a

Browse files
authored
Fix regression in guide_bins(reverse) (#6185)
* bump NA to back of key * add test * add news bullet * Fix interaction between #5912 and #6072
1 parent 8efc700 commit a62895a

File tree

5 files changed

+119
-2
lines changed

5 files changed

+119
-2
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
34
* New function family for setting parts of a theme. For example, you can now use
45
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
56
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This

R/geom-violin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ geom_violin <- function(mapping = NULL, data = NULL,
118118
check_numeric(draw_quantiles)
119119

120120
# Pass on to stat when stat accepts 'quantiles'
121-
stat <- check_subclass(stat, "Stat", current_call(), caller_env())
121+
stat <- validate_subclass(stat, "Stat", current_call(), caller_env())
122122
if ("quantiles" %in% stat$parameters()) {
123123
extra$quantiles <- draw_quantiles
124124
}

R/guide-bins.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ GuideBins <- ggproto(
211211
params$show.limits <- show.limits
212212

213213
if (params$reverse) {
214-
key <- key[rev(seq_len(nrow(key))), , drop = FALSE]
214+
ord <- seq_len(nrow(key))
215+
key <- vec_slice(key, rev(ord))
216+
# Put NA back in the trailing position
217+
key[params$aesthetic] <- vec_slice(key[params$aesthetic], c(ord[-1], ord[1]))
215218
key$.value <- 1 - key$.value
216219
}
217220

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
@@ -411,6 +411,22 @@ test_that("guides title and text are positioned correctly", {
411411
expect_doppelganger("legends with all title justifications", p)
412412
})
413413

414+
test_that("bin guide can be reversed", {
415+
416+
p <- ggplot(data.frame(x = c(0, 100)), aes(x, x, colour = x, fill = x)) +
417+
geom_point() +
418+
guides(
419+
colour = guide_bins(reverse = TRUE, show.limits = TRUE, order = 1),
420+
fill = guide_bins(
421+
reverse = TRUE, show.limits = FALSE, order = 2,
422+
override.aes = list(shape = 21)
423+
)
424+
)
425+
426+
expect_doppelganger("reversed guide_bins", p)
427+
428+
})
429+
414430
test_that("bin guide can be styled correctly", {
415431
df <- data_frame(x = c(1, 2, 3),
416432
y = c(6, 5, 7))

0 commit comments

Comments
 (0)