Skip to content

Round down breaks in scale_date to avoid misalignment #4430

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

Merged
merged 3 commits into from
Apr 21, 2021
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ggplot2 (development version)

* Fix bug in `scale_[x|y]_date()` where custom breaks functions that resulted in
fracional dates would get misaligned (@thomasp85, #3965)

* Fix bug in `scale_[x|y]_datetime()` where a specified timezone would be
ignored by the scale (@thomasp85, #4007)

Expand Down
8 changes: 8 additions & 0 deletions R/scale-date.r
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@ ScaleContinuousDate <- ggproto("ScaleContinuousDate", ScaleContinuous,
map = function(self, x, limits = self$get_limits()) {
self$oob(x, limits)
},
get_breaks = function(self, limits = self$get_limits()) {
breaks <- ggproto_parent(ScaleContinuous, self)$get_breaks(limits)
if (is.null(breaks)) {
return(NULL)
}
breaks <- floor(breaks)
breaks[breaks >= limits[1] & breaks <= limits[2]]
},
break_info = function(self, range = NULL) {
breaks <- ggproto_parent(ScaleContinuous, self)$break_info(range)
if (!(is.waive(self$secondary.axis) || self$secondary.axis$empty())) {
Expand Down