Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ggplot2 (development version)

* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
* Custom and raster annotation now respond to scale transformations, and can
use AsIs variables for relative placement (@teunbrand based on
@yutannihilation's prior work, #3120)
Expand Down
5 changes: 4 additions & 1 deletion R/guide-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,10 @@ GuideBins <- ggproto(
params$show.limits <- show.limits

if (params$reverse) {
key <- key[rev(seq_len(nrow(key))), , drop = FALSE]
ord <- seq_len(nrow(key))
key <- vec_slice(key, rev(ord))
# Put NA back in the trailing position
key[params$aesthetic] <- vec_slice(key[params$aesthetic], c(ord[-1], ord[1]))
key$.value <- 1 - key$.value
}

Expand Down
97 changes: 97 additions & 0 deletions tests/testthat/_snaps/guides/reversed-guide-bins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/testthat/test-guides.R
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ test_that("guides title and text are positioned correctly", {
expect_doppelganger("legends with all title justifications", p)
})

test_that("bin guide can be reversed", {

p <- ggplot(data.frame(x = c(0, 100)), aes(x, x, colour = x, fill = x)) +
geom_point() +
guides(
colour = guide_bins(reverse = TRUE, show.limits = TRUE, order = 1),
fill = guide_bins(
reverse = TRUE, show.limits = FALSE, order = 2,
override.aes = list(shape = 21)
)
)

expect_doppelganger("reversed guide_bins", p)

})

test_that("bin guide can be styled correctly", {
df <- data_frame(x = c(1, 2, 3),
y = c(6, 5, 7))
Expand Down