Skip to content

geom_area with negative y not working in ggplot2 3.2.0 #3390

Closed

Description

@vadimus202

In ggplot2 3.1.1 the area under the curve handles negative values

library(ggplot2)

set.seed(115)

ggplot(
    data.frame(
        x = 1:100,
        y = cumsum(rnorm(n = 100, mean = 0, sd = 3))
    ),
    aes(x, y)) +
    geom_area(fill = "pink", alpha = 0.5) +
    geom_path()

image

In ggplot2 3.2.0 something goes wrong:

library(ggplot2)

set.seed(115)

ggplot(
    data.frame(
        x = 1:100,
        y = cumsum(rnorm(n = 100, mean = 0, sd = 3))
    ),
    aes(x, y)) +
    geom_area(fill = "pink", alpha = 0.5) +
    geom_path()

image

Activity

  1. yutannihilation commented on Jul 4, 2019

    @yutannihilation
  2. clauswilke commented on Jul 4, 2019

    @clauswilke
    Member

    Rendered reprex below.

    @thomasp85 Is this somehow related to the rewritten polygon rendering code? We may have to consider a hotfix release, since this is a serious regression.

    library(ggplot2)
    
    d <- data.frame(
      x = 1:6,
      y = c(1, 2, 2, 1, 0, -1)
    )
    
    ggplot(d, aes(x, y)) +
      geom_area(fill = "pink", alpha = 0.5) +
      geom_point()

    ggplot(d, aes(x, y - 1)) +
      geom_area(fill = "pink", alpha = 0.5) +
      geom_point()

    Created on 2019-07-03 by the reprex package (v0.3.0)

  3. thomasp85 commented on Jul 4, 2019

    @thomasp85
    Member

    I’ll look into it.

  4. thomasp85 commented on Jul 4, 2019

    @thomasp85
    Member

    This is due to GeomArea/GeomRibbon now sorting their data in setup_data instead of in draw_panel. PositionStack changes the ordering of the data and that is no longer resolved as it comes after setup_data.

    There are two ways around this.

    1. Make sure PositionStack doesn't change the ordering of data
    2. Make a secondary sort in draw_panel()

    I generally prefer 1) as it is how I think positions should behave (i.e. not fiddle with data ordering), but it may have unforeseen consequences 🤷‍♂️

    I agree this should be fixed in a hot fix (and we really should have some tests to catch this) cc @hadley

  5. hadley commented on Jul 4, 2019

    @hadley
    Member
    1. sounds reasonable. And it shouldn't be too bad to do a patch release for this issue. Do we want to wait a week in case any other problems come in?
  6. thomasp85 commented on Jul 4, 2019

    @thomasp85
    Member

    Let's wait a week before we start release process

  7. added this to the ggplot2 3.2.1 milestone on Jul 4, 2019
  8. karawoo commented on Jul 5, 2019

    @karawoo
    Member

    If I recall correctly, the ordering in PositionStack exists to fix my first ever bug report (#1552) 🙂. So it is there for a reason, but it's possible that reason has been obviated by other changes since. I can try to look into it this weekend.

  9. karawoo commented on Jul 17, 2019

    @karawoo
    Member

    I've opened a PR that will address this, but in the meantime geom_ribbon() still works:

    library(ggplot2)
    
    set.seed(115)
    
    ggplot(
      data.frame(
        x = 1:100,
        y = cumsum(rnorm(n = 100, mean = 0, sd = 3))
      ),
      aes(x, y)) +
      geom_ribbon(aes(ymax = y, ymin = 0), fill = "pink", alpha = 0.5) +
      geom_path()

    Created on 2019-07-17 by the reprex package (v0.3.0)

  10. added
    bug
    on Jul 22, 2019
  11. yutannihilation commented on Jul 23, 2019

    @yutannihilation
    Member

    @thomasp85 @hadley

    Let's wait a week before we start release process

    Some weeks have passed. Do we start the process? While this issue should be hot-fixed, this might not be as serious as we thought at first in terms of the number of users affected, considering the fact there's no other issues filed than this one. So, if you are very busy (sorry, I don't think I can review #3401...), I think it's okay not to hurry so much.

    But, I'm a bit worrying about that the CRAN check is all red probably due to #3394 (, which seems already fixed by @paleolimbot). Do you get any serious warnings about this from CRAN people?

    https://cran.rstudio.com/web/checks/check_results_ggplot2.html

  12. thomasp85 commented on Jul 23, 2019

    @thomasp85
    Member

    I’m currently on vacation (this week and next). I’ll begin release once I’m back

  13. yutannihilation commented on Jul 23, 2019

    @yutannihilation
    Member

    OK. Have a nice vacation!

  14. added 3 commits that reference this issue on Aug 5, 2019
    be1031c
    522bfff
    b5e3494
  15. lock commented on Feb 9, 2020

    @lock

    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/

  16. locked and limited conversation to collaborators on Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions