Skip to content

Unsorted breaks in guide_coloursteps() #5152

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

Closed
teunbrand opened this issue Jan 18, 2023 · 0 comments · Fixed by #4879 or #5758
Closed

Unsorted breaks in guide_coloursteps() #5152

teunbrand opened this issue Jan 18, 2023 · 0 comments · Fixed by #4879 or #5758
Labels
bug an unexpected problem or unintended behavior guides 📏

Comments

@teunbrand
Copy link
Collaborator

teunbrand commented Jan 18, 2023

guide_coloursteps() and guide_bins() seems to give incorrect guide when breaks are not sorted in increasing direction.

In the example below, we can see the coloursteps aren't right. The same happens with continuous scales, but binned scales come with coloursteps by default, so that reprex was more minimal. This doesn't only happen when the breaks are sorted in descending order as in the example below, but this generally seems to happen when they're not increasing.

library(ggplot2)

p <- ggplot(mpg, aes(displ, hwy, colour = cty)) +
  geom_point()

p + scale_colour_viridis_b(breaks = seq(30, 10, by = -5))

You'd expect the guide to look like this:

p + scale_colour_viridis_b(breaks = seq(10, 30, by = 5))

Created on 2023-01-18 with reprex v2.0.2

I think the fix would be a simple sorting step in the guide training.

@teunbrand teunbrand added bug an unexpected problem or unintended behavior guides 📏 labels Jan 18, 2023
teunbrand added a commit to teunbrand/ggplot2 that referenced this issue Jan 18, 2023
teunbrand added a commit that referenced this issue Apr 24, 2023
The guide system, as the last remaining chunk of ggplot2, has been rewritten 
in ggproto. The axes and legends now inherit from a <Guide> class, which makes
them extensible in the same manner as geoms, stats, facets and coords 
(#3329, @teunbrand). In addition, the following changes were made:
    * Styling theme parts of the guide now inherit from the plot's theme 
      (#2728). 
    * Styling non-theme parts of the guides accept <element> objects, so that
      the following is possible: `guide_colourbar(frame = element_rect(...))`.
    * Primary axis titles are now placed at the primary guide, so that
      `guides(x = guide_axis(position = "top"))` will display the title at the
      top by default (#4650).
    * Unknown secondary axis guide positions are now inferred as the opposite 
      of the primary axis guide when the latter has a known `position` (#4650).
    * `guide_colourbar()`, `guide_coloursteps()` and `guide_bins()` gain a
      `ticks.length` argument.
    * In `guide_bins()`, the title no longer arbitrarily becomes offset from
      the guide when it has long labels.
    * The `order` argument of guides now strictly needs to be a length-1 
      integer (#4958).
    * More informative error for mismatched 
     `direction`/`theme(legend.direction = ...)` arguments (#4364, #4930).
    * `guide_coloursteps()` and `guide_bins()` sort breaks (#5152).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior guides 📏
Projects
None yet
1 participant