Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geom_dotplot dot layout with groups #1745

Closed
ironv opened this issue Sep 7, 2016 · 6 comments · Fixed by #4417
Closed

geom_dotplot dot layout with groups #1745

ironv opened this issue Sep 7, 2016 · 6 comments · Fixed by #4417
Assignees
Labels
bug an unexpected problem or unintended behavior layers 📈
Milestone

Comments

@ironv
Copy link

ironv commented Sep 7, 2016

geom_dotplot is not laying out the points correctly when there are 2 groups. See http://stackoverflow.com/questions/39375983/geom-dotplot-dot-layout-with-groups

require(data.table)
require(ggplot2)

set.seed(10000)
n <- 300

dt <- data.table(Duration=sample(100:800,n,replace=T), EndType=round(runif(n,min=.4)), Group=sample(c("GrpA","GrpB"),n,replace=T))
dt <- rbind(dt, dt[, -c("Group"), with=F][, Group:="All"])
dt[, ":="(Group=factor(Group, levels=c("All","GrpA","GrpB"), ordered=T), EndType=factor(EndType, levels=c(0,1)))]

g <- ggplot(dt, aes_string(x="Group", y="Duration")) + coord_flip() +
    geom_boxplot(aes(ymin=..lower.., ymax=..upper..), fatten=1.1, lwd=.1, outlier.shape=NA) + 
    geom_dotplot(aes(fill=EndType), binaxis="y", stackdir="center", stackgroups=T, method="histodot", binwidth=15, dotsize=.5) +
    scale_fill_manual(values=c("white","black"))
print(g)
@hadley
Copy link
Member

hadley commented Sep 15, 2016

Can you please create a minimal reprex?

@hadley hadley added the reprex needs a minimal reproducible example label Sep 15, 2016
@Ax3man
Copy link
Contributor

Ax3man commented Sep 21, 2016

This problem specifically occurs when using multiple fills/colors at the same time as a grouping on the x-axis.

A more minimal reprex:

ggplot(mtcars, aes(x = factor(gear), y = mpg, fill = factor(cyl))) +
  geom_dotplot(binaxis = "y", stackdir = "center",  stackgroups = TRUE,  method = "histodot")

It seems to me that when stackgroups = TRUE the relative x positions are calculated for all points together, without separation by the grouping on the x-axis. This can cause dots to 'float away' from the center.

When using stackdir = 'up' it is fine for the first cloud, but gets progressively worse towards the right.

ggplot(mtcars, aes(x = factor(gear), y = mpg, fill = factor(cyl))) +
  geom_dotplot(binaxis = "y", stackdir = "up", stackgroups = TRUE,  method = "histodot")

@hadley
Copy link
Member

hadley commented Sep 23, 2016

@wch any ideas?

@hadley hadley added bug an unexpected problem or unintended behavior layers 📈 and removed reprex needs a minimal reproducible example labels Jan 26, 2017
@wch
Copy link
Member

wch commented Nov 1, 2017

For this to work, the dotplot needs to be able do a calculation spanning all x groups, but within other grouping variables. I think only the x variable is special this way.

@eknud
Copy link

eknud commented Apr 24, 2018

Has a solution been presented here? Unclear if we've solved for this yet.

@thomasp85
Copy link
Member

Can users of geom_dotplot() please stress test the fix in #4417 - While it fixes the issue reported here I am unsure whether it has regressions somewhere else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants