Skip to content

Commit 7df8c69

Browse files
authored
Improve boundary handling (#6684)
* correct parenthesis * add contingent case * add news bullet
1 parent 155ffde commit 7df8c69

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Bug fixes
44

5+
* Fixed bug where `stat_bin(boundary)` was ignored (#6682).
56
* `geom_text()` and `geom_label()` accept expressions as the `label` aesthetic
67
(@teunbrand, #6638)
78
* Fixed regression where `draw_key_rect()` stopped using `fill` colours

R/bin.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
105105
} else {
106106
width <- (x_range[2] - x_range[1]) / (bins - 1)
107107
if (is.null(center)) {
108-
boundary <- boundary %||% x_range[1] - width / 2
108+
boundary <- boundary %||% (x_range[1] - width / 2)
109+
}
110+
# If `x_range` coincides with boundary we should
111+
# use exact `bins` instead of `bins - 1` to prevent misalignments.
112+
if (!is.null(boundary) && any(x_range %% width == boundary %% width)) {
113+
width <- (x_range[2] - x_range[1]) / bins
109114
}
110115
}
111116

0 commit comments

Comments
 (0)