Altair: Wrong sorting of rows if 'count()' is used

Created on 2 Sep 2019  路  1Comment  路  Source: altair-viz/altair

The sorting of rows seems to be broken if one axis is encoded as 'count()'.

Working Example with correct sorting of the rows:

import altair as alt
import pandas as pd

# init dataframe
df = pd.DataFrame({
    "type": ['a', 'b', 'c', 'b', 'c', 'b', 'a'],
    "value": [1,1,1,2,2,2,1]
})

# alt base
base = alt.Chart(df).encode(
    y='value:O',
    x='value',
    color='type',
)

alt.layer(
  base.mark_bar(),
  base.mark_text(dx=5).encode(text='value')
).facet(
  row=alt.Row('type', sort=['a', 'c', 'b'])
)

bug_correct

Once the encoding of x is changed to count() the explicit sorting order is ignored:

import altair as alt
import pandas as pd

# init dataframe
df = pd.DataFrame({
    "type": ['a', 'b', 'c', 'b', 'c', 'b', 'a'],
    "value": [1,1,1,2,2,2,1]
})

# alt base
base = alt.Chart(df).encode(
    y='value:O',
    x='count()',
    color='type',
)

alt.layer(
  base.mark_bar(),
  base.mark_text(dx=5).encode(text='value')
).facet(
  row=alt.Row('type', sort=['a', 'c', 'b'])
)

bug_wrong

bug vega-lite-related

Most helpful comment

This appears to be a vega-lite issue. I've reported it in https://github.com/vega/vega-lite/issues/5366

>All comments

This appears to be a vega-lite issue. I've reported it in https://github.com/vega/vega-lite/issues/5366

Was this page helpful?
0 / 5 - 0 ratings

Related issues

galloramiro picture galloramiro  路  3Comments

maxgerma picture maxgerma  路  3Comments

bmcfee picture bmcfee  路  3Comments

nielsmde picture nielsmde  路  4Comments

jtbaker picture jtbaker  路  3Comments