Skip to content

Commit ce3f435

Browse files
has2k1hadley
authored andcommitted
Fix jitter width and jitter height (#1777)
The problem was the %||% operator accepts single tokens and so care (bracketing as required) must be taken avoid miscalculations. Some other places in the code-base had it right. Fixes #1775
1 parent cb3bdde commit ce3f435

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
* Added `legend.box.spacing` to control the distance between the plot area
180180
and the legend area
181181

182+
* Fixed the jitter width and jitter height of `position_jitter` when the
183+
parameters are supplied by the user. (#1775, @has2k1)
184+
182185
# ggplot2 2.1.0
183186

184187
## New features

R/position-jitter.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ PositionJitter <- ggproto("PositionJitter", Position,
4444

4545
setup_params = function(self, data) {
4646
list(
47-
width = self$width %||% resolution(data$x, zero = FALSE) * 0.4,
48-
height = self$height %||% resolution(data$y, zero = FALSE) * 0.4
47+
width = self$width %||% (resolution(data$x, zero = FALSE) * 0.4),
48+
height = self$height %||% (resolution(data$y, zero = FALSE) * 0.4)
4949
)
5050
},
5151

R/position-jitterdodge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PositionJitterdodge <- ggproto("PositionJitterdodge", Position,
3838
required_aes = c("x", "y"),
3939

4040
setup_params = function(self, data) {
41-
width <- self$jitter.width %||% resolution(data$x, zero = FALSE) * 0.4
41+
width <- self$jitter.width %||% (resolution(data$x, zero = FALSE) * 0.4)
4242
# Adjust the x transformation based on the number of 'dodge' variables
4343
dodgecols <- intersect(c("fill", "colour", "linetype", "shape", "size", "alpha"), colnames(data))
4444
if (length(dodgecols) == 0) {

R/stat-boxplot.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
4646
non_missing_aes = "weight",
4747

4848
setup_params = function(data, params) {
49-
params$width <- params$width %||% resolution(data$x) * 0.75
49+
params$width <- params$width %||% (resolution(data$x) * 0.75)
5050

5151
if (is.double(data$x) && !has_groups(data) && any(data$x != data$x[1L])) {
5252
warning(

0 commit comments

Comments
 (0)