Skip to content

Stacked area charts not stacking #1552

Closed
@karawoo

Description

@karawoo

When I try to create a stacked area chart using the following code the segments don't stack, and they occlude each other instead.

library("ggplot2")
library("dplyr")

## Create data
set.seed(40)
dat <- data.frame(x = rep(c(1:10), 3),
                  var = rep(c("a", "b", "c"), 10),
                  y = round(runif(30, 1, 5)))

## Plot
ggplot(dat, aes(x = x, y = y, fill = var)) +
  geom_area(position = "stack")

unstacked_area

However if I reorder the rows so all of the var values are grouped together, it does create a stacked chart:

dat %>%
  arrange(var, x) %>%
  ggplot(aes(x = x, y = y, fill = var)) +
  geom_area(position = "stack")

stacked_area

Is this a bug, or is the ordering of the rows meant to matter like this?

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions