Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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)

* When using `geom_dotplot(binaxis = "x")` with a discrete y-variable, dots are
now stacked from the y-position rather than from 0 (@teunbrand, #5462)

* Legend titles no longer take up space if they've been removed by setting
`legend.title = element_blank()` (@teunbrand, #3587).

Expand Down
8 changes: 4 additions & 4 deletions R/geom-dotplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
# ymin, ymax, xmin, and xmax define the bounding rectangle for each stack
# Can't do bounding box per dot, because y position isn't real.
# After position code is rewritten, each dot should have its own bounding box.
yoffset <- if (is_mapped_discrete(data$y)) data$y else 0
data$xmin <- data$x - data$binwidth / 2
data$xmax <- data$x + data$binwidth / 2
data$ymin <- stackaxismin
data$ymax <- stackaxismax
data$y <- 0

data$ymin <- stackaxismin + yoffset
data$ymax <- stackaxismax + yoffset
data$y <- yoffset
} else if (params$binaxis == "y") {
# ymin, ymax, xmin, and xmax define the bounding rectangle for each stack
# Can't do bounding box per dot, because x position isn't real.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/testthat/test-geom-dotplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ test_that("geom_dotplot draws correctly", {
# Binning along y, with multiple grouping factors
dat2 <- data_frame(x = rep(factor(LETTERS[1:3]), 30), y = rnorm(90), g = rep(factor(LETTERS[1:2]), 45))

expect_doppelganger("bin x, three y groups, stack centerwhole",
ggplot(dat2, aes(y, x)) + geom_dotplot(binwidth = .25, binaxis = "x", stackdir = "centerwhole")
)
expect_doppelganger("bin y, three x groups, stack centerwhole",
ggplot(dat2, aes(x, y)) + geom_dotplot(binwidth = .25, binaxis = "y", stackdir = "centerwhole")
)
Expand Down