lets-plot
lets-plot copied to clipboard
geom_bar: aes 'fill' and trans 'log10' break y scale
Example:
n = 1000
np.random.seed(42)
data = {
"x": np.random.choice(["a", "b", "c"], p=[.49, .49, .02], size=n),
"g": np.random.choice(["X", "Y"], size=n),
}
ggplot(data, aes(x="x", fill="g")) + geom_bar() + scale_y_continuous(trans='log10')
Output:

Label values on y axis are much greater than expected. There is no such trouble if fill="g" or trans='log10' will be removed.
@ASmirnov-HORIS is this still the observed behavior in 4.3.0 ?
Yes. Now only powers of 10 are left on the y-axis, but the values are still larger than they should be.
The thing is, in case of 'stack' position adj. we sum transformed values. And if the transform is 'log' transform we have:
log(256) + log(236) ~= 4.78 (and "unlog": 10^4.78 ~= 60255)
instead of expected:
log(256 + 236) ~= 2.69