Skip to content

geom_area not working with negative values and two categories in 3.2.1 #3498

Closed

Description

@Hillerst

I am using geom_area for stacked area chart showing cumulative results for categories.
For some series the cumulative result turns negative from time to time and this have been working nicely with versions of ggplot2 until 3.2.0 was released. Some things have been fixed with the 3.2.1 release but I experince an issue when I have more than one category and using the category for the fill. I notice an ealier issue #3390 with similar problem but that has been closed now or ?

 packageVersion("ggplot2")
[1] ‘3.2.1’

# with one serie  (category A) it works as I expect

date <- as.Date(c("2019-07-31","2019-08-01","2019-08-02","2019-08-03"))
category <-rep(c("A"),4)
variable <-rep(c("cum_result"),4)
value <- c(0,2,3,-4)
data<- data.frame(date,category,variable,value)

ggplot(data, aes(x=date,y=value)) +
  geom_area(aes(x=date,y=value,fill=category),stat = "identity")

image

# addding a additional category B with values on the variable  shows the issue

date <- as.Date(c("2019-07-31","2019-07-31","2019-08-01","2019-08-01","2019-08-02","2019-08-02","2019-08-03","2019-08-03"))
category <-rep(c("A","B"),4)
variable <-rep(c("cum_result"),8)
value <- c(0,0,
           2,1,
           3,6,
           -4,3)

data<- data.frame(date,category,variable,value)

ggplot(data, aes(x=date,y=value)) +
  geom_area(aes(x=date,y=value,fill=category),stat = "identity")

image

Activity

  1. ptoche commented on Aug 22, 2019

    @ptoche

    Support for this has been discontinued. See: #2802 and #2803

  2. Hillerst commented on Aug 23, 2019

    @Hillerst
    Author

    I don't think its the same problem as described in issues 2802 and 2803
    I think the 3.2.0 version changed something in ordering of negative values. Using version 3.1.1 produces the following chart which is I think is correct.

    library(ggplot2)
    packageVersion("ggplot2")
    [1] ‘3.1.1’

    date <- as.Date(c("2019-07-31","2019-07-31","2019-08-01","2019-08-01","2019-08-02","2019-08-02","2019-08-03","2019-08-03"))
    category <-rep(c("A","B"),4)
    variable <-rep(c("cum_result"),8)
    value <- c(0,0,
    2,1,
    3,6,
    -4,3)

    data<- data.frame(date,category,variable,value)
    ggplot(data, aes(x=date,y=value)) +
    geom_area(aes(x=date,y=value,fill=category),stat = "identity")

    ggplot2 version 3 1 1

  3. clauswilke commented on Aug 23, 2019

    @clauswilke
    Member

    Yes, it is most likely caused by #3471.

  4. thomasp85 commented on Aug 24, 2019

    @thomasp85
    Member

    That one is obviously on me. We need some visual tests for these stacking situations

  5. added this to the ggplot2 3.3.0 milestone on Dec 18, 2019
  6. karawoo commented on Dec 18, 2019

    @karawoo
    Member

    @thomasp85 FYI #3401 looks like it solves this issue, but these stacking issues seem to be a whack-a-mole situation so I agree we need visual tests.

  7. thomasp85 commented on Dec 18, 2019

    @thomasp85
    Member

    Thanks! that will help with the debugging... srsly positions are the worst! seemingly simple and yet so so brittle

  8. added a commit that references this issue on Dec 19, 2019
    55ded0b
  9. added a commit that references this issue on Dec 20, 2019
    e6cbcc1
  10. lock commented on Jun 24, 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/

  11. locked and limited conversation to collaborators on Jun 24, 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions