BookmarkSubscribeRSS Feed

Creating Custom Bar Charts in SAS Graph Builder with Custom Sorting

Started ‎01-15-2025 by
Modified ‎01-15-2025 by
Views 1,518

Introduction

 

Hi everyone! 👋

 

In one of the recent projects I worked on, I developed a Model Interpretability dashboard to better understand how a machine learning model makes predictions and scores data. Among the various visualizations in the dashboard, one graph displayed the HyperSHAP values for a selected client, which could be chosen via a drop-down list. HyperSHAP values indicate how much each feature contributes to a prediction, with contributions being either positive or negative. For more information on Shapley values, refer to the references below. One challenge I faced was sorting the bars in this graph by their absolute values rather than their raw values.

In this article, @pathew and I will guide you through the steps to create a custom bar chart in SAS Visual Analytics. This chart will display HyperSHAP values (whether positive or negative) and order the bars based on their absolute values, using the data provided in the attached HyperSHAP_Values.csv file. The video below demonstrates the outcome we will be achieving by the end of the article:

 

 

To achieve this goal, we will leverage the power of SAS Graph Builder to create a custom graph object, which provides flexibility for visualizing your data. Let's get started!

 

 

Step 1: Create the Custom Bar Chart

 

To create a custom bar chart in SAS Graph Builder capable of sorting by a value different from what is displayed, we will employ a technique using two overlaid bar charts. Begin by accessing SAS Graph Builder through the Viya application menu under the Administration group, selecting Build Custom Graphs, and initiating a "New Custom Graph."

Drag and drop two Bar Chart elements from the Graph Elements pane onto the canvas.

 

pathew_0-1736861641999.png

 

To display only the desired values (positive or negative) and not absolute values, we will effectively "hide" the second bar chart. Achieve this by selecting the canvas to open the custom graph Options pane. Select "Bar Chart 2" from the drop-down list and set the "Transparency" to 100%.

 

pathew_0-1736956057178.png

 

 
Note: If you want to change the direction of the bars from vertical to horizontal, change the Direction for one of the two bar charts, and this will automatically change the direction of the remaining bar chart as well.
Then, switch to "Discrete Legend" in the drop-down list options, deselect the checkbox for Bar Chart 2, effectively concealing it and its legend.
 
pathew_7-1736862325628.png
 
Examine the Role Definitions for your custom graph in the Roles pane. It will feature one "Shared Role" utilized by both bar charts, along with a separate "Response" role for each. You can refine these role names to better align with SAS Visual Analytics terminology. For instance, change "Shared Role 1" to "Category", "Bar Chart 1 Response" to "Measure", and  "Bar Chart 2 Response" to "Hidden Measure." This hidden measure now allows us to assign actual values and absolute values to an individual chart object without displaying both, providing the desired sorting flexibility.
Finally, save the completed custom graph to a readily accessible location within SAS Content, making it available for import into SAS Visual Analytics.
 

Step 2: Use the custom graph in Visual Analytics

 
To use the custom graph in VA, we need to import it first. The steps to do that are the following:

1. In the Objects pane, accessible via the left pane, click on the Objects menu on the top-right corner and select Import custom graph

 

Screenshot 2025-01-15 091721.png

 

2. Select the custom graph from the folder where you saved it and click Open. The graph is now ready to be used and is displayed together with the other objects.
 
Screenshot 2025-01-15 092130.png

 

Note: The same steps are also explained in the documentation.
Therefore, we can now drag the custom bar chart onto the canvas and add data to it. If you use the data attached to the article, the role assignment reads:
  • Measure: Estimate
  • Hidden Measure: absEstimate
  • Category: Variable

Since this dataset contains the HyperSHAP values for five different customers, let's now add a Drop-down list to allow the user filter the bar chart based on the desired customer. We assign the Category role to the id variable, flag the Required option in the Options pane, and mark the custom bar chart in the Object Links section of the Actions pane.

 

Screenshot 2025-01-15 094414.png

 

 

Next, right-click on the graph and select absEstimate: Ascending (or Descending) for the Sort option. 

 

Screenshot 2025-01-15 093736.png

 

If you followed all the steps above, you should now have obtained a report very similar to the one visible in the video attached at the beginning of the article!

 

Conclusions

 

This ends the detailed explanation on how to create a custom bar chart in SAS Graph Builder to sort the data by a value different from what is being displayed. The one above is just an example, and you can customize the same procedure based on your data sets and needs!
Of course, feel free to comment on this article or reach out to us via email (Mattia.Guglielmelli@sas.com and Paul.Thewalt@sas.com) for any feedback or questions. I hope you found this article helpful, see you next time! 
😊

 

References

 

  • For more information on Shapley values, check out this article that also gives an overview of all the approximation methods that are available in SAS Viya to estimate them.
  • To know which are the model interpretability tools that can be applied to any model that is generated by a Supervised Learning node in SAS Model Studio, see here for an overview.   
  • If you want to know more on SAS Graph Builder, start by reading its documentation here.
Version history
Last update:
‎01-15-2025 11:36 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags