Skip to content

Commit

Permalink
Fix jitter width and jitter height (#1777)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
has2k1 authored and hadley committed Sep 27, 2016
1 parent cb3bdde commit ce3f435
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -179,6 +179,9 @@
* Added `legend.box.spacing` to control the distance between the plot area
and the legend area

* Fixed the jitter width and jitter height of `position_jitter` when the
parameters are supplied by the user. (#1775, @has2k1)

# ggplot2 2.1.0

## New features
Expand Down
4 changes: 2 additions & 2 deletions R/position-jitter.r
Expand Up @@ -44,8 +44,8 @@ PositionJitter <- ggproto("PositionJitter", Position,

setup_params = function(self, data) {
list(
width = self$width %||% resolution(data$x, zero = FALSE) * 0.4,
height = self$height %||% resolution(data$y, zero = FALSE) * 0.4
width = self$width %||% (resolution(data$x, zero = FALSE) * 0.4),
height = self$height %||% (resolution(data$y, zero = FALSE) * 0.4)
)
},

Expand Down
2 changes: 1 addition & 1 deletion R/position-jitterdodge.R
Expand Up @@ -38,7 +38,7 @@ PositionJitterdodge <- ggproto("PositionJitterdodge", Position,
required_aes = c("x", "y"),

setup_params = function(self, data) {
width <- self$jitter.width %||% resolution(data$x, zero = FALSE) * 0.4
width <- self$jitter.width %||% (resolution(data$x, zero = FALSE) * 0.4)
# Adjust the x transformation based on the number of 'dodge' variables
dodgecols <- intersect(c("fill", "colour", "linetype", "shape", "size", "alpha"), colnames(data))
if (length(dodgecols) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion R/stat-boxplot.r
Expand Up @@ -46,7 +46,7 @@ StatBoxplot <- ggproto("StatBoxplot", Stat,
non_missing_aes = "weight",

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

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

0 comments on commit ce3f435

Please sign in to comment.