From 2c3367dab08da577e39422cacb17e9b1fd0b28d6 Mon Sep 17 00:00:00 2001 From: Matthew Kay Date: Fri, 11 Feb 2022 21:47:36 -0600 Subject: [PATCH 1/3] tests for dotplot misalignment when stackratio != 1 (#4614) --- .../stack-center-stackratio-0-5.svg | 77 +++++++++++++++++++ .../stack-center-stackratio-1-5.svg | 77 +++++++++++++++++++ .../stack-centerwhole-stackratio-0-5.svg | 77 +++++++++++++++++++ .../stack-centerwhole-stackratio-1-5.svg | 77 +++++++++++++++++++ .../stack-down-stackratio-0-5.svg | 77 +++++++++++++++++++ .../stack-down-stackratio-1-5.svg | 77 +++++++++++++++++++ .../geom-dotplot/stack-up-stackratio-0-5.svg | 77 +++++++++++++++++++ .../geom-dotplot/stack-up-stackratio-1-5.svg | 77 +++++++++++++++++++ tests/testthat/test-geom-dotplot.R | 28 +++++++ 9 files changed, 644 insertions(+) create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg diff --git a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg new file mode 100755 index 0000000000..a794058a19 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.50 +-0.25 +0.00 +0.25 +0.50 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack center, stackratio = 0.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg new file mode 100755 index 0000000000..c3cacca1f3 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.50 +-0.25 +0.00 +0.25 +0.50 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack center, stackratio = 1.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg new file mode 100755 index 0000000000..b272f22f27 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.50 +-0.25 +0.00 +0.25 +0.50 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack centerwhole, stackratio = 0.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg new file mode 100755 index 0000000000..c1c8253c6a --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.50 +-0.25 +0.00 +0.25 +0.50 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack centerwhole, stackratio = 1.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg new file mode 100755 index 0000000000..775c456c62 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1.00 +-0.75 +-0.50 +-0.25 +0.00 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack down, stackratio = 0.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg new file mode 100755 index 0000000000..00bf0a2f9b --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1.00 +-0.75 +-0.50 +-0.25 +0.00 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack down, stackratio = 1.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg new file mode 100755 index 0000000000..77daf3352c --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack up, stackratio = 0.5 + + diff --git a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg new file mode 100755 index 0000000000..220b7c38c1 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + +-2 +-1 +0 +1 +2 +x +count +stack up, stackratio = 1.5 + + diff --git a/tests/testthat/test-geom-dotplot.R b/tests/testthat/test-geom-dotplot.R index 8049961508..461f83b520 100644 --- a/tests/testthat/test-geom-dotplot.R +++ b/tests/testthat/test-geom-dotplot.R @@ -125,6 +125,34 @@ test_that("geom_dotplot draws correctly", { ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole") + coord_flip() ) + # Stacking methods with stackratio < 1 + expect_doppelganger("stack up, stackratio = 0.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "up", stackratio = 0.5) + ) + expect_doppelganger("stack down, stackratio = 0.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "down", stackratio = 0.5) + ) + expect_doppelganger("stack center, stackratio = 0.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "center", stackratio = 0.5) + ) + expect_doppelganger("stack centerwhole, stackratio = 0.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole", stackratio = 0.5) + ) + + # Stacking methods with stackratio > 1 + expect_doppelganger("stack up, stackratio = 1.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "up", stackratio = 1.5) + ) + expect_doppelganger("stack down, stackratio = 1.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "down", stackratio = 1.5) + ) + expect_doppelganger("stack center, stackratio = 1.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "center", stackratio = 1.5) + ) + expect_doppelganger("stack centerwhole, stackratio = 1.5", + ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole", stackratio = 1.5) + ) + # Binning along x, with groups expect_doppelganger("multiple groups, bins not aligned", ggplot(dat, aes(x, fill = g)) + geom_dotplot(binwidth = .4, alpha = .4) From 4fe178a2a2d247b633b3c7e142c63a4ab677d22f Mon Sep 17 00:00:00 2001 From: Matthew Kay Date: Fri, 11 Feb 2022 21:51:40 -0600 Subject: [PATCH 2/3] correctly adjust dot positions for stackratio != 1 when stackdir != "up", closes #4614 --- R/geom-dotplot.r | 2 +- R/grob-dotstack.r | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/R/geom-dotplot.r b/R/geom-dotplot.r index e866e834a0..a087e6cb4c 100644 --- a/R/geom-dotplot.r +++ b/R/geom-dotplot.r @@ -288,7 +288,7 @@ GeomDotplot <- ggproto("GeomDotplot", Geom, ggname("geom_dotplot", dotstackGrob(stackaxis = stackaxis, x = tdata$x, y = tdata$y, dotdia = dotdianpc, - stackposition = tdata$stackpos, stackratio = stackratio, + stackposition = tdata$stackpos, stackdir = stackdir, stackratio = stackratio, default.units = "npc", gp = gpar(col = alpha(tdata$colour, tdata$alpha), fill = alpha(tdata$fill, tdata$alpha), diff --git a/R/grob-dotstack.r b/R/grob-dotstack.r index dc25dc24eb..05907b751f 100644 --- a/R/grob-dotstack.r +++ b/R/grob-dotstack.r @@ -4,6 +4,7 @@ dotstackGrob <- function( stackaxis = "y", dotdia = unit(1, "npc"), # Dot diameter in the non-stack axis, should be in npc stackposition = 0, # Position of each dot in the stack, relative to origin + stackdir = "up", # Stacking direction ("up", "down", "center", or "centerwhole") stackratio = 1, # Stacking height of dots (.75 means 25% dot overlap) default.units = "npc", name = NULL, gp = gpar(), vp = NULL) { @@ -17,7 +18,7 @@ dotstackGrob <- function( warn("Unit type of dotdia should be 'npc'") grob(x = x, y = y, stackaxis = stackaxis, dotdia = dotdia, - stackposition = stackposition, stackratio = stackratio, + stackposition = stackposition, stackdir = stackdir, stackratio = stackratio, name = name, gp = gp, vp = vp, cl = "dotstackGrob") } # Only cross-version reliable way to check the unit of a unit object @@ -31,14 +32,27 @@ makeContext.dotstackGrob <- function(x, recording = TRUE) { xmm <- convertX(x$x, "mm", valueOnly = TRUE) ymm <- convertY(x$y, "mm", valueOnly = TRUE) + # When stacking up (or down), stackratios != 1 will cause the bottom (top) + # edge of the first dot in a stack to no longer touch the origin, as + # stackpositions are expanded or contracted away from the dotstack's origin. + # The stackoffset corrects that misalignment so that the first dot just + # touches the dotstack's origin. + if (is.null(x$stackdir) || x$stackdir == "up") { + stackoffset <- (1 - x$stackratio) / 2 + } else if (x$stackdir == "down") { + stackoffset <- -(1 - x$stackratio) / 2 + } else { + stackoffset <- 0 + } + if (x$stackaxis == "x") { dotdiamm <- convertY(x$dotdia, "mm", valueOnly = TRUE) - xpos <- xmm + dotdiamm * (x$stackposition * x$stackratio + (1 - x$stackratio) / 2) + xpos <- xmm + dotdiamm * (x$stackposition * x$stackratio + stackoffset) ypos <- ymm } else if (x$stackaxis == "y") { dotdiamm <- convertX(x$dotdia, "mm", valueOnly = TRUE) xpos <- xmm - ypos <- ymm + dotdiamm * (x$stackposition * x$stackratio + (1 - x$stackratio) / 2) + ypos <- ymm + dotdiamm * (x$stackposition * x$stackratio + stackoffset) } circleGrob( From adb4431156116a2a7c6ad8406543f37728ed14ad Mon Sep 17 00:00:00 2001 From: Matthew Kay Date: Tue, 15 Mar 2022 20:15:39 -0500 Subject: [PATCH 3/3] condense tests for stackratio != 1 (#4614) --- NEWS.md | 3 + .../stack-center-stackratio-0-5.svg | 77 ------------------- .../stack-center-stackratio-1-5.svg | 77 ------------------- .../stack-centerwhole-stackratio-0-5.svg | 77 ------------------- .../stack-centerwhole-stackratio-1-5.svg | 77 ------------------- .../stack-down-stackratio-0-5.svg | 77 ------------------- .../stack-down-stackratio-1-5.svg | 77 ------------------- .../geom-dotplot/stack-up-stackratio-0-5.svg | 77 ------------------- .../geom-dotplot/stack-up-stackratio-1-5.svg | 77 ------------------- .../_snaps/geom-dotplot/stackratio-1-5.svg | 74 ++++++++++++++++++ tests/testthat/test-geom-dotplot.R | 41 ++++------ 11 files changed, 90 insertions(+), 644 deletions(-) delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg delete mode 100755 tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg create mode 100755 tests/testthat/_snaps/geom-dotplot/stackratio-1-5.svg diff --git a/NEWS.md b/NEWS.md index 6579c613b1..9b99fc9b93 100644 --- a/NEWS.md +++ b/NEWS.md @@ -53,6 +53,9 @@ * `geom_contour()` now accepts a function in the `breaks` argument (@eliocamp, #4652). +* Dots in `geom_dotplot()` are now correctly aligned to the baseline when + `stackratio != 1` and `stackdir != "up"` (@mjskay, #4614) + # ggplot2 3.3.5 This is a very small release focusing on fixing a couple of untenable issues that surfaced with the 3.3.4 release diff --git a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg deleted file mode 100755 index a794058a19..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-0-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.50 --0.25 -0.00 -0.25 -0.50 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack center, stackratio = 0.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg deleted file mode 100755 index c3cacca1f3..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-center-stackratio-1-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.50 --0.25 -0.00 -0.25 -0.50 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack center, stackratio = 1.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg deleted file mode 100755 index b272f22f27..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-0-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.50 --0.25 -0.00 -0.25 -0.50 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack centerwhole, stackratio = 0.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg deleted file mode 100755 index c1c8253c6a..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-centerwhole-stackratio-1-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --0.50 --0.25 -0.00 -0.25 -0.50 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack centerwhole, stackratio = 1.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg deleted file mode 100755 index 775c456c62..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-0-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --1.00 --0.75 --0.50 --0.25 -0.00 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack down, stackratio = 0.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg deleted file mode 100755 index 00bf0a2f9b..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-down-stackratio-1-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --1.00 --0.75 --0.50 --0.25 -0.00 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack down, stackratio = 1.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg deleted file mode 100755 index 77daf3352c..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-0-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0.00 -0.25 -0.50 -0.75 -1.00 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack up, stackratio = 0.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg deleted file mode 100755 index 220b7c38c1..0000000000 --- a/tests/testthat/_snaps/geom-dotplot/stack-up-stackratio-1-5.svg +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0.00 -0.25 -0.50 -0.75 -1.00 - - - - - - - - - - --2 --1 -0 -1 -2 -x -count -stack up, stackratio = 1.5 - - diff --git a/tests/testthat/_snaps/geom-dotplot/stackratio-1-5.svg b/tests/testthat/_snaps/geom-dotplot/stackratio-1-5.svg new file mode 100755 index 0000000000..09021c0550 --- /dev/null +++ b/tests/testthat/_snaps/geom-dotplot/stackratio-1-5.svg @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-1.0 +-0.5 +0.0 +0.5 +1.0 + + + + + + + + +3 +6 +9 +x +count +stackratio = 1.5 + + diff --git a/tests/testthat/test-geom-dotplot.R b/tests/testthat/test-geom-dotplot.R index 461f83b520..13b5c58787 100644 --- a/tests/testthat/test-geom-dotplot.R +++ b/tests/testthat/test-geom-dotplot.R @@ -125,34 +125,6 @@ test_that("geom_dotplot draws correctly", { ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole") + coord_flip() ) - # Stacking methods with stackratio < 1 - expect_doppelganger("stack up, stackratio = 0.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "up", stackratio = 0.5) - ) - expect_doppelganger("stack down, stackratio = 0.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "down", stackratio = 0.5) - ) - expect_doppelganger("stack center, stackratio = 0.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "center", stackratio = 0.5) - ) - expect_doppelganger("stack centerwhole, stackratio = 0.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole", stackratio = 0.5) - ) - - # Stacking methods with stackratio > 1 - expect_doppelganger("stack up, stackratio = 1.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "up", stackratio = 1.5) - ) - expect_doppelganger("stack down, stackratio = 1.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "down", stackratio = 1.5) - ) - expect_doppelganger("stack center, stackratio = 1.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "center", stackratio = 1.5) - ) - expect_doppelganger("stack centerwhole, stackratio = 1.5", - ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole", stackratio = 1.5) - ) - # Binning along x, with groups expect_doppelganger("multiple groups, bins not aligned", ggplot(dat, aes(x, fill = g)) + geom_dotplot(binwidth = .4, alpha = .4) @@ -254,3 +226,16 @@ test_that("geom_dotplot draws correctly", { ggplot(dat2, aes(0, x)) + geom_dotplot(binwidth = .4, binaxis = "y", stackdir = "center") )) }) + +test_that("stackratio != 1 works", { + df <- data.frame(x = c(rep(1, 3), rep(2, 2))) + + expect_doppelganger("stackratio = 1.5", + ggplot(df) + + geom_hline(yintercept = 0) + + geom_dotplot(aes(x), binwidth = 0.5, stackdir = "down", stackratio = 1.5, fill = NA) + + geom_dotplot(aes(x + 3), binwidth = 0.5, stackdir = "up", stackratio = 1.5, fill = NA) + + geom_dotplot(aes(x + 6), binwidth = 0.5, stackdir = "center", stackratio = 1.5, fill = NA) + + geom_dotplot(aes(x + 9), binwidth = 0.5, stackdir = "centerwhole", stackratio = 1.5, fill = NA) + ) +})