Skip to content

Commit caafb8d

Browse files
committed
Avoid setdiff() and multiplication in binned break calculation
1 parent 0d0de37 commit caafb8d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

R/scale-.r

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,10 +1075,13 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
10751075
# Ensure terminal bins are same width if limits not set
10761076
if (is.null(self$limits)) {
10771077
# Remove calculated breaks if they coincide with limits
1078-
breaks <- setdiff(breaks, limits)
1078+
breaks <- breaks[!breaks %in% limits]
10791079
nbreaks <- length(breaks)
10801080
if (nbreaks >= 2) {
1081-
new_limits <- c(2 * breaks[1] - breaks[2], 2 * breaks[nbreaks] - breaks[nbreaks - 1])
1081+
new_limits <- c(
1082+
breaks[1] + (breaks[1] - breaks[2]),
1083+
breaks[nbreaks] + (breaks[nbreaks] - breaks[nbreaks - 1])
1084+
)
10821085
if (breaks[nbreaks] > limits[2]) {
10831086
new_limits[2] <- breaks[nbreaks]
10841087
breaks <- breaks[-nbreaks]

0 commit comments

Comments
 (0)