Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 bug in `geom_dotplot()` where dots would be positioned wrong with
`stackgroups = TRUE` (@thomasp85, #1745)

* Make sure position_jitter creates the same jittering independent of whether it
is called by name or with constructor (@thomasp85, #2507)

Expand Down
16 changes: 11 additions & 5 deletions R/geom-dotplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,31 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
stackdots <- function(a) a - 1 - floor(max(a - 1) / 2)
stackaxismin <- -.5
stackaxismax <- .5
} else {
abort(glue('{params$stackdir} is not a recognized value for `stackdir`. Use "up", "down", "center", or "centerwhole"'))
}


# Fill the bins: at a given x (or y), if count=3, make 3 entries at that x
data <- data[rep(1:nrow(data), data$count), ]

# Next part will set the position of each dot within each stack
# If stackgroups=TRUE, split only on x (or y) and panel; if not stacking, also split by group
plyvars <- params$binaxis %||% "x"
stackaxis <- setdiff(c("x", "y"), plyvars)
plyvars <- c(plyvars, "PANEL")
if (is.null(params$stackgroups) || !params$stackgroups)
plyvars <- c(plyvars, "group")

if (stackaxis == "x") {
plyvars <- c(plyvars, "x")
}

# Within each x, or x+group, set countidx=1,2,3, and set stackpos according to stack function
data <- dapply(data, plyvars, function(xx) {
xx$countidx <- 1:nrow(xx)
xx$stackpos <- stackdots(xx$countidx)
xx
})
xx$countidx <- 1:nrow(xx)
xx$stackpos <- stackdots(xx$countidx)
xx
})


# Set the bounding boxes for the dots
Expand Down
2 changes: 1 addition & 1 deletion tests/figs/deps.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- vdiffr-svg-engine: 1.0
- vdiffr: 0.3.3
- freetypeharfbuzz: 0.2.5
- freetypeharfbuzz: 0.2.6
Loading