0

I have created a simple bar chart showing household income and the count of each. I'm trying to sort the y-axis labels (household income) to be in descending order such as:

  • '$150,000+'
  • '$100,000 - $149,999'
  • '$50,000 - $99,999'
  • '$25,000 - $49,999'
  • '$0 - $24,999'

These income labels are all strings. I have tried the following, but it isn't sorting it properly. Here is my code and the output:

def yes_func():
    chart_yes = alt.Chart(df_yes).mark_bar().encode(
        x = alt.X('Count:Q'),
        y = alt.Y('Household Income:N', sort='-x')
    )
    return chart_yes

yes_func()

enter image description here

I'm assuming there's an easy fix to this, but the Altair documentation online isn't much help unfortunately.

0 Answers0