Skip to content

Commit aebbece

Browse files
committed
Fix geom_dotplot y limit calculations
The computed y limits depend on both the group & panel. This ensures that the scale trainning does not get wrong (global y limits) input. Fixes #1618. Closes #1622. By @has2k1.
1 parent 0a31f9b commit aebbece

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
* Quantile lines in geom_violin() are no longer affected by the alpha aesthetic
8282
(@mnbram, #1714)
8383

84+
* Fixed problem with `geom_dotplot()` when facetting and binning on the
85+
y-axis. (#1618, @has2k1)
86+
8487
# ggplot2 2.1.0
8588

8689
## New features

R/geom-dotplot.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom,
238238
# works. They're just set to the standard x +- width/2 so that dot clusters
239239
# can be dodged like other geoms.
240240
# After position code is rewritten, each dot should have its own bounding box.
241-
data <- plyr::ddply(data, "group", transform,
241+
data <- plyr::ddply(data, c("group", "PANEL"), transform,
242242
ymin = min(y) - binwidth[1] / 2,
243243
ymax = max(y) + binwidth[1] / 2)
244244

tests/testthat/test-dotplot.r

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,17 @@ test_that("NA's result in warning from stat_bindot", {
6363
expect_warning(ggplot_build(ggplot(dat, aes(x)) + geom_dotplot(binwidth = .2)),
6464
"Removed 2 rows.*stat_bindot")
6565
})
66+
67+
test_that("When binning on y-axis, limits depend on the panel", {
68+
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
69+
geom_dotplot(binaxis='y')
70+
71+
b1 <- ggplot_build(p + facet_wrap(~am))
72+
b2 <- ggplot_build(p + facet_wrap(~am, scales = "free_y"))
73+
74+
equal_limits1 <- (b1$panel$ranges[[1]]$y.range == b1$panel$ranges[[2]]$y.range)
75+
equal_limits2 <- (b2$panel$ranges[[1]]$y.range == b2$panel$ranges[[2]]$y.range)
76+
77+
expect_true(all(equal_limits1))
78+
expect_false(all(equal_limits2))
79+
})

0 commit comments

Comments
 (0)