Skip to content

Allow PositionStack to specify the directions on negatives and positives seperately #3607

Closed
@yutannihilation

Description

@yutannihilation

Context: I need this to finish #3529 (comment)

PositionStack allows to flip the stacking direction by reverse parameter, but it forces the data on the positive side and on the negative side have the same direction.

ggplot2/R/position-stack.r

Lines 191 to 204 in 528a374

if (any(negative)) {
neg <- collide(neg, NULL, "position_stack", pos_stack,
vjust = params$vjust,
fill = params$fill,
reverse = params$reverse
)
}
if (any(!negative)) {
pos <- collide(pos, NULL, "position_stack", pos_stack,
vjust = params$vjust,
fill = params$fill,
reverse = params$reverse
)
}

However, it's not a rare case we want to stack them in the opposite direction (i.e. reverse the direction only on the negative side) to draw data properly. geom_area() is the very example for this. I wonder if PositionStack can accept these.

For the interface, I don't come up with a nice idea yet, but it would be something like:

geom_area(
  position = position_stack(reverse = c(positive = FALSE, positive = TRUE))
)

or

geom_area(
  position = position_stack(reverse = TRUE, mirrored = TRUE)
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions