Skip to content

geom_area position_stack order appears to have changed #2778

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

Closed
ptoche opened this issue Jul 26, 2018 · 4 comments
Closed

geom_area position_stack order appears to have changed #2778

ptoche opened this issue Jul 26, 2018 · 4 comments

Comments

@ptoche
Copy link

ptoche commented Jul 26, 2018

The default order of the data in geom_area() has changed. The order is no longer the order shown in the manual https://ggplot2.tidyverse.org/reference/position_stack.html

Was that intended? Is it documented?

series <- data.frame(
    time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
    type = rep(c('a', 'b', 'c', 'd'), 4),
    value = rpois(16, 10)
)
library(ggplot2)
ggplot(series, aes(time, value)) +
    geom_area(aes(fill = type))

ggplot(series, aes(time, value)) + 
    geom_area(aes(fill = type), position = position_stack(reverse = TRUE))

Created on 2018-07-26 by the reprex package (v0.2.0).

Compare the above with the relevant part of the manual:

# Stacking is also useful for time series
series <- data.frame(
  time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
  type = rep(c('a', 'b', 'c', 'd'), 4),
  value = rpois(16, 10)
) 
ggplot(series, aes(time, value)) +
  geom_area(aes(fill = type))

https://ggplot2.tidyverse.org/reference/position_stack-5.png

@ptoche
Copy link
Author

ptoche commented Jul 30, 2018

An example from plots I made a couple of years ago.

Before:

figure_1_1_old

After:

figure_1_1_new

@karawoo
Copy link
Member

karawoo commented Jul 30, 2018

It looks the same in the manual to me?

screen shot 2018-07-30 at 8 30 31 am

I do think the stack order changed at some point but it was a while ago in 2.2.0.

@hadley hadley closed this as completed Jul 30, 2018
@ptoche
Copy link
Author

ptoche commented Aug 1, 2018

@karawoo, You're probably right. My plots are from February 2015, so this may well be an old change.

The example from the manual confused me because I got a plot that looked quite different and assumed it was a common cause. The real reason is that the data used in the example is random. It might be useful to set a seed before the data is created to make it clearer, e.g.

set.seed(1)
series <- data.frame(
    time = c(rep(1, 4),rep(2, 4), rep(3, 4), rep(4, 4)),
    type = rep(c('a', 'b', 'c', 'd'), 4),
    value = rpois(16, 10)
)
ggplot(series, aes(time, value)) +
    geom_area(aes(fill = type))

@lock
Copy link

lock bot commented Jan 28, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants