Fix misalignment in geom_dotplot when stackratio != 1 and stackdir != "up"#4734
Fix misalignment in geom_dotplot when stackratio != 1 and stackdir != "up"#4734hadley merged 4 commits intotidyverse:mainfrom
Conversation
hadley
left a comment
There was a problem hiding this comment.
Thanks for working on this 😄. As well addressing the comments, can you please add a bullet to the top of NEWS.md? It should briefly describe the change and end with (@yourname, #issuenumber).
| ggplot(dat, aes(x)) + geom_dotplot(binwidth = .4, stackdir = "centerwhole") + coord_flip() | ||
| ) | ||
|
|
||
| # Stacking methods with stackratio < 1 |
There was a problem hiding this comment.
Can you please make this a separate test? (The existing huge test unfortunately isn't a good pattern to follow). And can you please also create the smallest possible dataset needed to demonstrate the problem?
There was a problem hiding this comment.
Sure, done --- I pulled out the four tests for stackratio = 1.5 into a separate test with a single doppelganger on a simplified dataset that should be sensitive to problems with any of the four values of stackdir. Dunno if you would rather those be four separate small doppelgangers or one merged doppelganger as I have done.
| 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", |
There was a problem hiding this comment.
I think one test with non-default stack ratio would be adequate. Visual tests are expensive to maintain so we really want to keep them as minimal as possible.
|
Happy to, thanks for the feedback! I've added a NEWS entry and updated the tests based on your comments. |
hadley
left a comment
There was a problem hiding this comment.
Visual test is perfect, thanks!
* master: (320 commits) Orientation-aware key glyphs (tidyverse#4757) Fix warning in geom_violin with draw_quantiles (tidyverse#4654) Fix misalignment in geom_dotplot when stackratio != 1 and stackdir != "up" (tidyverse#4734) Replace coord_equal in scale-identity.r (tidyverse#4759) Unified message format in `geom_smooth()` (tidyverse#4634) Add parentheses to mentions of binned_scale in scale-alpha and scale-viridis documentation (tidyverse#4735) Update geom-boxplot.r (tidyverse#4744) Remove unneeded backslash from diamonds docs (tidyverse#4711) Re-document Warn on unsupported geoms in annotate() (tidyverse#4721) Re-document Add Trump to presidential terms dataset (tidyverse#4702) Corrects bins / binwidth override documentation (tidyverse#4720) Update infrastructure to new best practices (tidyverse#4748) remove stringsAsFactor for the mapped_discrete as.data.frame method (tidyverse#4750) Workflow updates (tidyverse#4747) Ensure output is numeric even if ifelse clause is NA (tidyverse#4692) Add non_missing_aes to geom_tile (tidyverse#4683) Pass on binwidth and height to geom (tidyverse#4671) Check for range == NULL - happens if no data has been added to plot (tidyverse#4682) ...
This PR fixes #4614.
The problem
For
geom_dotplot()/ thedotstackgrob, the(1 - x$stackratio) / 2adjustment on these lines...ggplot2/R/grob-dotstack.r
Lines 34 to 42 in c89c265
...is there because otherwise when
stackratio != 1andstackdir = "up", the base of the first dot in a stack will no longer touch the baseline. This is becausestackratiowill expand (or contract) the dot stack away (or towards) the origin.However, currently this adjustment only works correctly for
stackdir = "up". For example, here isstackdir = "down"(for other examples, see #4614):Notice how the top dot in each stack does not touch
y = 0as it should.The solution
The solution is that the
(1 - x$stackratio) / 2adjustment needs to depend onstackdir:"up", it should remain(1 - x$stackratio) / 2"down", it should be reversed:-(1 - x$stackratio) / 2"center"and"centerwhole", it is unnecessary, and should be0.This PR implements that change, and includes test cases to ensure the adjustment is correct when
stackratio < 1and whenstackratio > 1.