Skip to content

Commit 46cc970

Browse files
authored
Round down breaks in scale_date to avoid misalignment (#4430)
1 parent ff31715 commit 46cc970

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 (development version)
22

3+
* Fix bug in `scale_[x|y]_date()` where custom breaks functions that resulted in
4+
fracional dates would get misaligned (@thomasp85, #3965)
5+
36
* Fix bug in `scale_[x|y]_datetime()` where a specified timezone would be
47
ignored by the scale (@thomasp85, #4007)
58

R/scale-date.r

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ ScaleContinuousDate <- ggproto("ScaleContinuousDate", ScaleContinuous,
387387
map = function(self, x, limits = self$get_limits()) {
388388
self$oob(x, limits)
389389
},
390+
get_breaks = function(self, limits = self$get_limits()) {
391+
breaks <- ggproto_parent(ScaleContinuous, self)$get_breaks(limits)
392+
if (is.null(breaks)) {
393+
return(NULL)
394+
}
395+
breaks <- floor(breaks)
396+
breaks[breaks >= limits[1] & breaks <= limits[2]]
397+
},
390398
break_info = function(self, range = NULL) {
391399
breaks <- ggproto_parent(ScaleContinuous, self)$break_info(range)
392400
if (!(is.waive(self$secondary.axis) || self$secondary.axis$empty())) {

0 commit comments

Comments
 (0)