Tip of the Week

Expressions are not just for the X and Y axis

 

You may already be aware that you can configure the X and Y axis to use a predefined expression, rather than the raw data values from a column. This expression can perform complex aggregations, calculations between one column and other columns in the data table, or logical calculations based off the values in particular column(s).

 

What you may not be aware of is that you can use the same expression syntax in other axis, like the Color axis, or Size axis.  This becomes very valuable when you are trying to color or size, for example, on something that is not built into the raw data.

Let’s assume you have a Bar Chart that shows a distribution of values:

 

You can choose to color based off another categorical column in your data set, but that may not be what you want to display in this chart. If you have many bars, you may want to color bars to put them into different bins, “Low”, “Normal”, and “High” or similar.

You can do this in a variety of ways. The way I see most people do this is use the Tag Panel to create a Tag Collection , and then identify the different bars (in this case Z-scores) as either “Low”, “Normal”, or “High”. (We will discuss Tags in a future Post and they are also discussed in detail in both SP151 TIBCO Spotfire Distributing Analytics and Data Cleaning, Transforming, and Pre-processing in TIBCO Spotfire).

That will work, and the benefit is you can now use those tags in another chart if needed. The downside is any new data loaded may not be applied to your tags as you want them to be.

However another option, which will get executed against new or replaced data,  is to use an expression directly in the color-axis.  To do this right-click on the color axis selector and select ‘Custom Expression…”

 

You can then enter any expression you want.  In this particular case, we want to color bar into three segments, based off values from the x-axis column.  You can use values from any column, we just happen to use the x-axis column here to keep it simple.  The following is the expression used:

<case  when ([Z-score])>(2.0) then "High" when ([Z-score])<(-2.0) then "Lo" else "Normal" end>

 

 

This expression will check the x-axis value and will identify the bars with values over 2 as “High”, the bars with values under -2 as “Low” and everything else as “Normal”. The names used to display inside the color selector shown in the legend.


If you need to you can now adjust the colors for the three segments in the properties dialog.

 

The expression will now be re-calculated to update the colorings when needed (when new data is added, when filtering is performed, etc…)

 

Expressions can also be used in the size axis.  Although this expression is much more complicated, the following expression is used in the size-axis to size a marker based off the number of highly discounted items.

 

 

This expression, as well as the entire concept of Expressions, is discussed and explained in detail in the training course SP141 : TIBCO Spotfire Computational Analytics and the webinar  Custom Expressions in TIBCO Spotfire

 

 

Comments

 

Sumeet said:

Nice post Kevin. I found this very helpful. One follow-up question that I have is that can we use "Over" in the custom expression when writing it in the color or size axis? One place where that could possibly be useful would be (using your example), if I wanted to color "high", "low" etc not with respect to a fixed number, but the with average z-score for all data values on the X-Axis.

October 22, 2009 1:14 PM
 

Kevin Hanegan said:

Hi Sumeet,

Im glad you found the post helpful. To answer your question, you most certainly can use OVER as well as any Node Navigation method inside color or size axes, or any axis that is applicable.

October 22, 2009 3:35 PM
 

hvmarck said:

Unfortunately you can't change the order so the legend reads "Low","Normal","High" in that order! Any chance this is going to change in the near future?

December 9, 2009 7:29 AM
 

Kevin Hanegan said:

For expressions, the only way to update the sort order is to update the expression, and output the values you want in the order you want. So, for example, if you want "Low","Normal", "High", then you need to update the expression to do something like the following:

<case  when ([Z-score])<(-2.0) then "Low" when (([Z-score])>=(-2.0)) AND (([Z-score])<=(2.0)) then "Normal" else "High" end>

I can submit an enhancement request for you to be able to apply a custom sort order to an expression.

Kevin

December 9, 2009 8:00 AM
 

hvmarck said:

Isn't the order alfabetical by default (I just tried your expression and it doesn't work for me)?

December 9, 2009 8:50 AM
 

Kevin Hanegan said:

Sorry, you are right, I should have tested it before I sent the reply :)

Then, the  only way to accomplish what you want to do would be to not use a custom expression and instead build the expression as a new calculated column, where you can apply a custom sort order.

For the enhancement request, I will submit to have the ability to apply a custom sort order to an expression using the same dialog as you have available for built-in columns.

Thanks,

Kevin

December 9, 2009 10:16 AM
 

Kelli Scott said:

Hi, I've found a lot of the topics discussed in these forums helpful however they are always geared to charts.  I would like to see some tips for cross charts.  

In particualar - I have a question on what would be the custom expression to calculate a variance column in the vertical column.  ie the data table will have many rows, and one column for time (eg month 1,2,3 etc). I cant work out how to show a month movement - is this some type of uniquecount / over expression??

Aprreciate any help!!!

Thanks

December 9, 2009 12:08 PM
 

Kevin Hanegan said:

Hi Kelli,

Im not exactly clear what kind of 'movement' you mean, are you referring to things like moving averages? Would it be possible to post a very small dataset sample and what your desired output may look like and I can take a look (no need to draw it just explain what the cell values would represent)?

Thanks,

Kevin

December 11, 2009 8:28 AM
 

Michelle Lacy said:

I realize this is an thread almost a year old, but since I have a question related to Kelli's last post, I decided to jump in..

I have a cross tab table and I want to color cells based on a column that is not displayed in the cross tab visualizaton.  I notice that the functionality showed for the  bar chart is not available for the crosstab table.  Is this possible?

November 17, 2010 5:13 PM
 

sarah said:

Hi,

I am trying to do something similar with a scatter plot however the only availiable column is axis.color. I am unable to use calculated columns such as a z score. How were you able to use other columns?

November 21, 2011 3:04 PM
 

uggkensington said:

http://www.uggkensingtons.org/

http://www.uggkensingtons.org/ugg-fox-fur-short-boots-5531-c-54.html | UGG Fox Fur Short Boots 5531

http://www.uggkensingtons.org/ugg-kensington-boots-5678-c-2.html | UGG Kensington Boots 5678

http://www.uggkensingtons.org/ugg-rainier-eskimo-boots-5189-c-85.html | UGG Rainier Eskimo Boots 5189

http://www.uggkensingtons.org/ugg-retro-cargo-boots-1895-c-3.html | UGG Retro Cargo Boots 1895

December 27, 2011 8:22 PM
 

uggskensingtonsale said:

www.uggskensingtonsale.org

www.uggskensingtonsale.orgugg-adirondack-boots-ii-c-6.html | UGG Adirondack Boots II

www.uggskensingtonsale.orgugg-adirondack-tall-boots-c-11.html | UGG Adirondack Tall Boots

www.uggskensingtonsale.orgugg-amberlee-boots-c-34.html | UGG Amberlee Boots

www.uggskensingtonsale.orgugg-annabelle-boots-c-35.html |

December 28, 2011 4:39 AM
 

uggretrocargosale said:

January 4, 2012 8:52 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Syndication

Other Spotfire Blogs

Spotfire's interactive information visualization and analytic solutions give users a remarkable experience for quickly and easily querying data and reporting results for superior business intelligence. From portfolio management and customer retention programs to key processes such as CRM, marketing, research, bioinformatics, yield and asset management and design for manufacturing, enterprises around the world rely on Spotfire's business analytics software to improve operational performance.

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center