Skip to content
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

breaks_pretty() will return zero-range limit #455

Merged
merged 3 commits into from
Oct 21, 2024
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 @@
# scales (development version)

* `breaks_pretty()` will return the input limit when it has no range (#446)
* `transform_exp()` now has more sensible breaks, available in `breaks_exp()`
(@teunbrand, #405).
* The scales package now keeps track of known palettes. These can be retrieved
Expand Down
3 changes: 3 additions & 0 deletions R/breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ breaks_pretty <- function(n = 5, ...) {
force_all(n, ...)
n_default <- n
function(x, n = n_default) {
if (zero_range(as.numeric(x))) {
return(x[1])
}
breaks <- pretty(x, n, ...)
names(breaks) <- attr(breaks, "labels")
breaks
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ test_that("breaks_pretty() arguments are forcely evaluated on each call #81", {
expect_equal(subfun2(1), subfuns[[2]](1))
})

test_that("exponential breaks give sensible values", {
test_that("breaks_pretty() returns input when given zero-width range (#446)", {
expect_equal(breaks_pretty()(c(1, 1)), 1)
})

test_that("exponential breaks give sensible values", {
x <- breaks_exp()(c(0, 2))
expect_equal(x, c(0, 0.5, 1, 1.5, 2))

Expand Down
Loading