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

Horizontal bar graphs: Match default stack order in legend as well #1837

Closed
dpprdan opened this issue Oct 6, 2016 · 9 comments
Closed

Horizontal bar graphs: Match default stack order in legend as well #1837

dpprdan opened this issue Oct 6, 2016 · 9 comments
Labels
Milestone

Comments

@dpprdan
Copy link

@dpprdan dpprdan commented Oct 6, 2016

According to the v2.2.0 announcement: "position_stack() and position_fill() now stack values in the reverse order of the grouping, which makes the default stack order match the legend." IMHO this should also be true for horizontal bar graphs.

df <- data.frame(
  x = factor(c(1, 1, 2, 2)),
  y = c(1, 3, 2, 1),
  grp = c("a", "b", "a", "b")
)

ggplot(data = df, aes((x), y, fill = (grp), label = y)) +
  geom_col() +
  geom_text(position = "stack_point") + 
  theme(legend.position = "bottom") +
  coord_flip()

horizontal_bar_graph_order

position = "stack_point" borrowed from #1821.

@hadley hadley added the bug label Oct 6, 2016
@hadley hadley added this to the v2.2.0 milestone Oct 6, 2016
@hadley
Copy link
Member

@hadley hadley commented Oct 6, 2016

@thomasp85 we forgot about this important case. Any ideas? forcats::fct_rev() doesn't help as it flips order in both plot and legend.

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Oct 7, 2016

Honestly I don't think we can have it both ways, so we need to decide on the preferred default.

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Oct 7, 2016

We could add a reverse argument to the scale constructors that would make it easy to reverse legend order. An ugly "fix" but it would solve it partly

@hadley
Copy link
Member

@hadley hadley commented Oct 7, 2016

Would reversing legend order work? It doesn't seem great to have labels "b", "a". And reversing the mapping between colour and letter would just flip the colours in both locations.

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Oct 7, 2016

Come to think of it the natural thing would be to have a switch in position_stack. We cannot make this automatic as neither Coord, Scale, nor Position is aware of each other's presence and it would thus degenerate into horrible coord_flip checks everywhere (we already have enough of those)

@hadley
Copy link
Member

@hadley hadley commented Oct 7, 2016

Agreed. Let me merge my stacking changes, and then one of us can add a reverse argument.

@hadley hadley closed this in f24770f Oct 10, 2016
@hadley
Copy link
Member

@hadley hadley commented Oct 10, 2016

@thomasp85 I also changed the default order to stack from inside-out (i.e. from close to axis to far away). That looks better to me eye because you get a mirror image if each x value has the same levels.

@thomasp85
Copy link
Member

@thomasp85 thomasp85 commented Oct 10, 2016

I'm unsure what you mean - skimming the diff it seems default behaviour is preserved (I.e. Stacking from top to bottom)

@hadley
Copy link
Member

@hadley hadley commented Oct 10, 2016

Negative values stack in the opposite direction now

charles-plessy added a commit to charles-plessy/smallCAGEqc that referenced this issue Dec 19, 2016
`position = position_stack(reverse = TRUE)` is needed
otherwise the error bars are plotted at wrong locations.

See <tidyverse/ggplot2#1837>
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants