Skip to content

Commit 125b1e0

Browse files
authored
Revert default resolution(), add argument (#5765)
* add `discrete` as argument to `resolution()` * explicitly declare `discrete` * add test * document * add news bullet
1 parent f1e84cb commit 125b1e0

16 files changed

+32
-21
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* Patterns and gradients are now also enabled in `geom_sf()`
1818
(@teunbrand, #5716).
1919
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
20+
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
21+
behaviour. Whether mapped discrete vectors should be treated as having
22+
resolution of 1 is controlled by the new `discrete` argument.
2023
* Fixed bug in `guide_bins()` and `guide_coloursteps()` where discrete breaks,
2124
such as the levels produced by `cut()`, were ordered incorrectly
2225
(@teunbrand, #5757).

R/geom-boxplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ GeomBoxplot <- ggproto("GeomBoxplot", Geom,
189189
data$flipped_aes <- params$flipped_aes
190190
data <- flip_data(data, params$flipped_aes)
191191
data$width <- data$width %||%
192-
params$width %||% (resolution(data$x, FALSE) * 0.9)
192+
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
193193

194194
if (isFALSE(params$outliers)) {
195195
data$outliers <- NULL

R/geom-dotplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
193193

194194
setup_data = function(data, params) {
195195
data$width <- data$width %||%
196-
params$width %||% (resolution(data$x, FALSE) * 0.9)
196+
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
197197

198198
# Set up the stacking function and range
199199
if (is.null(params$stackdir) || params$stackdir == "up") {

R/geom-errorbar.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ GeomErrorbar <- ggproto("GeomErrorbar", Geom,
4545
data$flipped_aes <- params$flipped_aes
4646
data <- flip_data(data, params$flipped_aes)
4747
data$width <- data$width %||%
48-
params$width %||% (resolution(data$x, FALSE) * 0.9)
48+
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
4949
data <- transform(data,
5050
xmin = x - width / 2, xmax = x + width / 2, width = NULL
5151
)

R/geom-errorbarh.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ GeomErrorbarh <- ggproto("GeomErrorbarh", Geom,
6060

6161
setup_data = function(data, params) {
6262
data$height <- data$height %||%
63-
params$height %||% (resolution(data$y, FALSE) * 0.9)
63+
params$height %||% (resolution(data$y, FALSE, TRUE) * 0.9)
6464

6565
transform(data,
6666
ymin = y - height / 2, ymax = y + height / 2, height = NULL

R/geom-hex.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ GeomHex <- ggproto("GeomHex", Geom,
6666
if (!is.null(data$width)) {
6767
dx <- data$width[1] / 2
6868
} else {
69-
dx <- resolution(data$x, FALSE)
69+
dx <- resolution(data$x, FALSE, TRUE)
7070
}
7171
# Adjust for difference in width and height of regular hexagon. 1.15 adjusts
7272
# for the effect of the overlapping range in y-direction on the resolution
7373
# calculation
7474
if (!is.null(data$height)) {
7575
dy <- data$height[1] / sqrt(3) / 2
7676
} else {
77-
dy <- resolution(data$y, FALSE) / sqrt(3) / 2 * 1.15
77+
dy <- resolution(data$y, FALSE, TRUE) / sqrt(3) / 2 * 1.15
7878
}
7979

8080
hexC <- hexbin::hexcoords(dx, dy, n = 1)

R/geom-raster.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ GeomRaster <- ggproto("GeomRaster", Geom,
9494
}
9595

9696
# Convert vector of data to raster
97-
x_pos <- as.integer((data$x - min(data$x)) / resolution(unclass(data$x), FALSE))
98-
y_pos <- as.integer((data$y - min(data$y)) / resolution(unclass(data$y), FALSE))
97+
x_pos <- as.integer((data$x - min(data$x)) / resolution(data$x, FALSE))
98+
y_pos <- as.integer((data$y - min(data$y)) / resolution(data$y, FALSE))
9999

100100
data <- coord$transform(data, panel_params)
101101

R/geom-tile.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ GeomTile <- ggproto("GeomTile", GeomRect,
109109
extra_params = c("na.rm"),
110110

111111
setup_data = function(data, params) {
112-
data$width <- data$width %||% params$width %||% resolution(data$x, FALSE)
113-
data$height <- data$height %||% params$height %||% resolution(data$y, FALSE)
112+
data$width <- data$width %||% params$width %||% resolution(data$x, FALSE, TRUE)
113+
data$height <- data$height %||% params$height %||% resolution(data$y, FALSE, TRUE)
114114

115115
transform(data,
116116
xmin = x - width / 2, xmax = x + width / 2, width = NULL,

R/geom-violin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ GeomViolin <- ggproto("GeomViolin", Geom,
135135
data$flipped_aes <- params$flipped_aes
136136
data <- flip_data(data, params$flipped_aes)
137137
data$width <- data$width %||%
138-
params$width %||% (resolution(data$x, FALSE) * 0.9)
138+
params$width %||% (resolution(data$x, FALSE, TRUE) * 0.9)
139139
# ymin, ymax, xmin, and xmax define the bounding rectangle for each group
140140
data <- dapply(data, "group", transform,
141141
xmin = x - width / 2,

R/position-jitter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ PositionJitter <- ggproto("PositionJitter", Position,
6868
seed <- self$seed
6969
}
7070
list(
71-
width = self$width %||% (resolution(data$x, zero = FALSE) * 0.4),
72-
height = self$height %||% (resolution(data$y, zero = FALSE) * 0.4),
71+
width = self$width %||% (resolution(data$x, zero = FALSE, TRUE) * 0.4),
72+
height = self$height %||% (resolution(data$y, zero = FALSE, TRUE) * 0.4),
7373
seed = seed
7474
)
7575
},

0 commit comments

Comments
 (0)