hadley/ggplot2 — Issue #257: Incorrect values with stacking and log scales
Author: wch
Created: 2011-11-04 04:04:40+00:00
State: open

This is with the development branch. I just tried making a stacked area graph with a log y scale, and found that the plotted values were way, way off. It was only after I tried it that I realized that stacking with a log scale either makes no sense, or will be very misleading -- though I personally can't rule out the possibility that _some_ stacked log-scale graph could make sense.

At any rate, it seems to me that ggplot should (A) give a warning or error when you attempt this, and (B) not make a graph with incorrect values.

In this example, I have data that grows exponentially. The largest summed value is 4e+10. It shows fine with a linear-scale. When I add the log scale, the growth is a straight line, which is correct, but the y values are wrong -- it shows the largest value is about 1e+40. It looks like the lowest piece of the stack is scaled correctly, then the subsequent pieces are drawn with the same scaling, instead of being scaled properly for their positions in the stack.

```
dat <- data.frame(group=rep(LETTERS[1:4], each=10),
x=rep(1:10,4),
y=rep(10^(1:10),4))

# Linear scale
ggplot(dat, aes(x=x, y=y, fill=group)) + geom_area()

# Log scale
ggplot(dat, aes(x=x, y=y, fill=group)) + geom_area() + scale_y_log10()
```

The same happens with geom_bar:

```
ggplot(dat, aes(x=factor(x), y=y, fill=group)) + geom_bar()

ggplot(dat, aes(x=factor(x), y=y, fill=group)) + geom_bar() + scale_y_log10()
```