Hi,
Really enjoying Altair but I've run into a bug when attempt to display stacked bars, some of which contain negative values.
Here is a minimal test case that demonstrates the problem.
import pandas as pd
from altair import Chart
data = pd.DataFrame({'amount': [-2000, 3000, 2000, 4000, 3000, 5000, 1000, 2000],
'quarter': ['Q1', 'Q1', 'Q2', 'Q2', 'Q3', 'Q3', 'Q1', 'Q1'],
'type': ['N', 'C', 'N', 'C', 'N', 'C', 'N', 'C'],
'year': [2016, 2016, 2016, 2016, 2016, 2016, 2017, 2017]})
Chart(data).mark_bar().encode(
color='type:N',
column='quarter:O',
x='year:N',
y='sum(amount):Q',
)
Which produces this view:

If you remove the sum() aggregation from the y axis, the negative values are displayed but you lose the stacking.
Chart(data).mark_bar().encode(
color='type:N',
column='quarter:O',
x='year:N',
y='amount:Q',
)
Which looks like this:

Anyone else run into this issue?
Hi,
Thanks for reporting. However, this is not a bug.
Semantically, a stack bar chart shows the "sum" of non-negative values, so it should only work if you use summable aggregation (sum, count, distinct, ...).
If you have negative values, you cannot use stack bar chart without running into problems.
(For example, if you have 1D stacked bar with two values, -20 and 20 and thus the sum is zero.
It's impossible to show that there are two subgroups that adds up to zero overall.)
Btw, in the future, we might add better warning about this to help users understand encoding limitations for data with negative values better. (See https://github.com/vega/vega-lite/issues/1833.)
Are you sure this is not a bug? Here is the expected view generated correctly in Tableau using the same data.

The latest version of Vega (3.0.0-beta.26) has an updated stack transform that can properly handle negative numbers. As a result, Vega-Lite 2.0 will ultimately "do the right thing" here.
Thanks @jheer and @kanitw for the clarification. Closing as question/vega-lite
Most helpful comment
The latest version of Vega (3.0.0-beta.26) has an updated stack transform that can properly handle negative numbers. As a result, Vega-Lite 2.0 will ultimately "do the right thing" here.