Sample 59480: Sorting a grouped bar chart by a measure in SAS® Visual Analytics
Overview
In SAS® Visual Analytics Designer, grouped bar charts can be sorted only by category. You cannot sort on the measure as long as the chart is grouped. This sample explains how you can create a custom graph that enables you to sort on either the category or the measure in grouped charts. In order to use the custom graph in your report, you make it available as an object. This sample includes the steps to create the custom graph and to add the graph as an object.
Here is an example of a bar chart with the ability to sort on the measure.
About the sample data
The data used for the sample is based on the SASHELP.CARS table. The graph uses the Type and DriveTrain categories, and the Frequency measure. In order to follow along with the steps, you can load this table in to your SAS® LASR™ Analytic Server.
Creating the graph using the Custom Graph Builder
- In a new SAS Visual Analytics report, click the arrow next to the Home button in the upper left corner of the application, and select Custom Graph Builder.
- In the New Custom Graph dialog box, select Bar Chart and click OK. The chart is automatically named Bar Chart 1.
- From the Graph Elements pane, drag another Bar Chart on top of Bar Chart 1. This new bar chart is automatically named Bar Chart 2.
- Click the Properties tab and select the name of the container that holds the two bar charts (named A1). For Overlaid plot colors, select All graphs start with the same color, as shown in the following display.
- On the Properties tab, change the selected object to Discrete Legend, as shown in the following display:
- Deselect Bar Chart 1, as shown in the following display:
- On the Properties tab, select Bar Chart 1.
- Under Plot Display, set the Transparency slider to 100%.
- Click the Role Definitions tab, and perform these steps:
- For Bar Chart 2, click Add Role, select Group, and click OK.
- By default, the two charts should have a shared category role (Shared Role 1). To create a shared measure role, click the arrow next to the Measure role in Bar Chart 2, select Create Shared Role with Another Role, and select Measure. Keep the default Role Name of Shared Role 2. Click OK.
- For Bar Chart 1, delete both the Group role and the Data Tip role by clicking the arrow next to each one and selecting Delete.
When you are finished making changes to the roles, the Role Definitions tab should look like this:
- On the Properties tab, select Bar Chart 2.
- Under Groups, select Stack, as shown in the following display:
- Select File ► Save. If you see a warning message about the lattice roles, click Remove Lattice Roles and Continue. Provide a name for the graph, and remember the saved location.
Adding the custom graph to the Objects pane in SAS Visual Analytics Designer
- Log on to SAS Visual Analytics Designer.
- On the Objects tab, click the arrow and select Show or Hide Objects, as shown in the following display:
- Click Select Custom and navigate to where you saved the graph. Select the graph and click OK. You should now see your graph beneath the Custom section of the Show or Hide Objects dialog box. Click OK to return to the report.
- From the Objects tab, drag the custom graph on to the report canvas.
- Select the Data tab and add the Cars sample table (or your own data source).
- With the custom bar chart active, select the Roles tab. Select Type for Shared Role 1, Frequency for Shared Role 2, and DriveTrain for Bar Chart 2 Group, as shown in the following display:
- On the graph, click Frequency in the upper left corner to open the pop-up menu. Select Sort Ascending or Sort Descending to sort on the measure.
Additional resources
Custom graphs are documented in the SAS Visual Analytics: User's Guide. For links to all of the available documentation for SAS Visual Analytics, see the SAS Visual Analytics Product Documentation page.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Date Modified: | 2016-12-16 12:43:14 |
Date Created: | 2016-12-07 16:16:46 |
Operating System and Release Information
SAS System | SAS Visual Analytics | Microsoft® Windows® for x64 | 7.3 | | 9.4 TS1M3 | |
Linux for x64 | 7.3 | | 9.4 TS1M3 | |