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 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
15 changes: 10 additions & 5 deletions R/geom-dotplot.r
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ geom_dotplot <- function(mapping = NULL, data = NULL,
if (stackgroups && method == "dotdensity" && binpositions == "bygroup")
message('geom_dotplot called with stackgroups=TRUE and method="dotdensity". You probably want to set binpositions="all"')

stackdir <- arg_match0(stackdir, c("up", "down", "center", "centerwhole"), "stackdir")
layer(
data = data,
mapping = mapping,
Expand Down Expand Up @@ -210,23 +211,27 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
stackaxismax <- .5
}


# 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