Skip to content

Unsorted breaks in guide_coloursteps() #5152

@teunbrand

Description

@teunbrand

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorguides 📏

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions