hadley/ggplot2 — Issue #280: Stacking for geom_area doesn't properly handle missing entries
Author: wch
Created: 2011-12-07 07:15:47+00:00
State: open

With a a stacked area graph, it requires an entry at every x for every group. If for a given x value, one group doesn't have an entry in the data frame, then it will behave as though the y value of that group at that x is zero.

The pictures will illustrate better:

```R

dat <- data.frame(
g=rep(LETTERS[1:3], each=4),
x=rep(1:4, 3),
y=rep(3:14))

# Remove row with g=B, x=3
dat <- dat[-7,]
dat

# Lines all look straight
ggplot(dat, aes(x=x, y=y, colour=g)) + geom_line()

# With a stacked area graph, there's a dip at x=3
ggplot(dat, aes(x=x, y=y, fill=g)) + geom_area()
```

Test code:

```R
test_that("Stacked area graph interpolates missing values", {
dat <- data.frame(
g=rep(LETTERS[1:3], each=4),
x=rep(1:4, 3),
y=rep(3:14))

# Remove row with g=B, x=3
dat <- dat[-7,]

p <- ggplot_build(ggplot(dat, aes(x=x, y=y, fill=g)) + geom_area())

topgroup_y <- with(p$data[[1]], y[x==3 & group==3] )
expect_equal(topgroup_y, 27)
})
```

I think fixing this one would require doing some interpolation. Perhaps solving this one is better left to the large changes to stacking code in the future?