Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Stacked area charts not stacking #1552
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")
However if I reorder the rows so all of the
dat %>% arrange(var, x) %>% ggplot(aes(x = x, y = y, fill = var)) + geom_area(position = "stack")
Is this a bug, or is the ordering of the rows meant to matter like this?
It sort of makes weird sense as the order at each x-value follows the order it occurs in in the data. I would suggest we add a sorting step to
@hadley thoughts? It might change the appearance of some plots, though I would argue that the benefit of the bug fix and sorting would alleviate that...