Skip to content

Fix regression in guide_bins(reverse) #6185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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).
* New function family for setting parts of a theme. For example, you can now use
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
Expand Down
2 changes: 1 addition & 1 deletion R/geom-violin.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
check_numeric(draw_quantiles)

# Pass on to stat when stat accepts 'quantiles'
stat <- check_subclass(stat, "Stat", current_call(), caller_env())
stat <- validate_subclass(stat, "Stat", current_call(), caller_env())

Check warning on line 121 in R/geom-violin.R

View check run for this annotation

Codecov / codecov/patch

R/geom-violin.R#L121

Added line #L121 was not covered by tests
if ("quantiles" %in% stat$parameters()) {
extra$quantiles <- draw_quantiles
}
Expand Down
5 changes: 4 additions & 1 deletion R/guide-bins.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,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 @@ -411,6 +411,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
Loading