tidyverse / ggplot2

An implementation of the Grammar of Graphics in R
https://ggplot2.tidyverse.org
Other
6.39k stars 2k forks source link

Sort scale and viewscale limits #5921

Open teunbrand opened 1 month ago

teunbrand commented 1 month ago

This PR aims to fix #5918.

Briefly, continuous_scale() now sorts the limits and position guides get passed sorted ranges.

The order of the limits should now only matter when choosing e.g. limits = c(NA, 10) to substitute the NA for the data limits. Examples below are from the issue.

Regular scale, flipped limits:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

ggplot() + scale_x_continuous(limits = c(10, 0))

Reverse scale, sorted limits:

ggplot() + scale_x_reverse(limits = c(0, 10))

Created on 2024-05-31 with reprex v2.1.0