Jump to content

Sort Bars in a Side by Side Bar Chart


Annie Thwing

Recommended Posts

I have a side by side bar chart, comparing a set of data (in red) to that of a regional benchmark (in gray).

My goal is to sort this data by the value of the red bar, and to only show the Top 6 values of this bar - with the corresponding regional measurements as bars next to that data for comparison.

The problem I am running into is that when I use a combination of "Sort bars by value" and the Show/Hide selector to only show the Top "X", it does not sort by the red percentage, but rather as the total of my subset + the regional benchmark.

The custom expression to find the top 6 specifically excludes the benchmark data, the order is only correct when the regional benchmark data is not included at all in the visualization.

Is there a way to sort by one specific bar (red) in a side by side bar chart, or any workarounds that people have found

The "n" in the attached picture, is the number corresponding to the red bar percentage, and the expression to find it is what the "Top 6" custom expression currently is.

Link to comment
Share on other sites

Hi

For the sorting, try this:

1) switch visualization to Combination Chart (by right-clicking on visualization background)

2) in Appearance tab: sort X axis by: whatever the red bar represents (in my example, USA)

This fixes the ordering by red bar only.

For the filtering, I could not think of a simple solution. I used a calculated column via an expression function. (This is similar to a TERR data function but slightly simpler to handle). The expression function is called MYFUN_filterCategories and outputs a boolean: True if the category corresponds to the top 3 in the red bars, False otherwise.

The column calculated with the expression function is called [include]. In order to filter by it, I used the Limit data by expression in the Data tab of the Properties (right-click on the bar chart at the bottom).

In my example, the X axis is [Category], the colour-by is [Country] and the red bar corresponds to [Country]=USA. These, and the number of top ranks you want to keep, are inputs to the expression function, and can be adapted - e.g. I used 3 instead of 6 because I had only five groups.

Gaia

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...