Skip to content
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 a bug in `position_jitter()` where different jitters would be applied to
different position aesthetics of the same axis (@thomasp85, #2941)

* `ggsave()` now uses ragg to render raster output if ragg is available
(@thomasp85, #4388)

Expand Down
13 changes: 12 additions & 1 deletion R/position-jitter.r
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ PositionJitter <- ggproto("PositionJitter", Position,
trans_x <- if (params$width > 0) function(x) jitter(x, amount = params$width)
trans_y <- if (params$height > 0) function(x) jitter(x, amount = params$height)

with_seed_null(params$seed, transform_position(data, trans_x, trans_y))
# Make sure x and y jitter is only calculated once for all position aesthetics
x_aes <- intersect(ggplot_global$x_aes, names(data))
x <- if (length(x_aes) == 0) 0 else data[[x_aes[1]]]
y_aes <- intersect(ggplot_global$y_aes, names(data))
y <- if (length(y_aes) == 0) 0 else data[[y_aes[1]]]
dummy_data <- new_data_frame(list(x = x, y = y), nrow(data))
fixed_jitter <- with_seed_null(params$seed, transform_position(dummy_data, trans_x, trans_y))
x_jit <- fixed_jitter$x - x
y_jit <- fixed_jitter$y - y

# Apply jitter
transform_position(data, function(x) x + x_jit, function(x) x + y_jit)
}
)