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_dodge2()` where `NA` values in thee data would cause an
error (@thomasp85, #2905)

* Fix a bug in `position_jitter()` where different jitters would be applied to
different position aesthetics of the same axis (@thomasp85, #2941)

Expand Down
2 changes: 1 addition & 1 deletion R/position-dodge2.r
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ find_x_overlaps <- function(df) {
overlaps[1] <- counter <- 1

for (i in seq_asc(2, nrow(df))) {
if (df$xmin[i] >= df$xmax[i - 1]) {
if (is.na(df$xmin[i]) || is.na(df$xmax[i - 1]) || df$xmin[i] >= df$xmax[i - 1]) {
counter <- counter + 1
}
overlaps[i] <- counter
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-position-dodge2.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ test_that("width of groups is computed per facet", {

expect_true(all(width == (0.9 / 3) * 0.9))
})

test_that("NA values are given their own group", {
df <- data.frame(
xmin = c(1, 2, NA, NA),
xmax = c(1, 2, NA, NA)
)
expect_equal(find_x_overlaps(df), seq_len(4))
})