BookmarkSubscribeRSS Feed

How to display derived variables in a SAS Visual Analytics custom graph

Started ‎05-03-2016 by
Modified ‎05-03-2016 by
Views 4,127

In one of my previous posts I described how to place 4 measures on the same plot.  A modified butterfly plot to be exact.  Lots of people commented about how useful this was.  So for this post, I decided to once again, show how to place multiple measures on the same plot...but with a twist! 

 

In my last post, all four measures were represented by the same type of graph: a bar chart.  However, in the data visualization world, it is very common to want to blend different types of plots together, while representing common variables between the various plots.  

 

Often times in visualizing data, there are derived variables that are sourced from other variables within the dataset.  For example, when looking at international trade data there are usually two variables: Imports and Exports.  However a common THIRD variable within trade data is "Balance of Trade" which is the difference between the monetary value of exports and imports.  The "Balance of Trade" is therefore derived from the exports and imports variables.  It can be very useful to include a derived variable alongside it's source variables in visualizations.  The question becomes, how to effectively display a derived variable in association with its source variables?

 

In this post, I'll demonstrate a way to do this using the SAS Visual Analytics Custom Graph Builder. 

 

For this demonstration, I will be using data from the population projection data provided by the US Census.   In this data, you will see the columns "Births" and "Deaths."  Since both of these variables have a significant effect on the population projection, perhaps you would want to plot the births and deaths columns on a graph and the derived DIFFERENCE between these two variables.

 

With this in mind, using SAS Visual Analytics and the Custom Graph Builder, I created the following visualization:

 

FINAL_CHART.png

 

Notice how the Births and Deaths are represented as offsetting bars in the same year, however the DIFFERENCE between Births and Deaths is represented by the line that stretches across the bar charts. This is particularly useful as the line plot shares the X-axis (year) with the bar charts, however it has its own y-axis on the right.  Using this graph, the report consumer can see the shift in the line plot's slope and also see the two bar chart's that are driving the line's movement.  So now when the report consumer views the number of births vs. deaths (in say 2017) and asks "What's the difference?" ... the answer is also displayed on the line plot.

 

 

How to create the graph

NOTE: these instructions are for SAS Visual Analytics 7.2

 

Setting up

Start by accessing the VA Graph Builder from the right panel in VA Designer (look for Custom Graph) or from the

object tab in the left panel in Visual Analytics Designer.

 

Graph_Builder_Button_outline.png

Once in Visual Analytics 7.2 Graph Builder, there is a Bar Chart graph available in the New Custom Graph gallery. From this gallery, on the initial page, select the Bar Chart graph.

 

BAR_CHART_SELECTION.png

 

Since we know that our final graph will have two bar charts on it, (one above, and one below the 'zero' value on the y-axis) we can go ahead and add a second Bar Chart graph onto the Graph Builder's canvas.  Simply click the 'Bar Chart' object from the available objects on left hand pane.  Once selected, drag the Bar Chart onto the Graph Builder's center canvas:

 

ADD_SECOND_BAR_CHART.png

 

We now have two of the three graph objects necessary to create the "What's The Difference" custom graph.  Next, we will add the third object (a line chart) to the graph.  As we did with the bar chart, click the 'Line Chart' object from the available objects on left hand pane.  Once selected, drag the Line Chart onto the Graph Builder's center canvas:

 

ADD_LINE_CHART.png

 

Excellent!  Now all three graph objects needed to create the "What's The Difference" custom graph are in play.  However we will need to edit some of the properties of the line plot in order for the graph to render correctly in SAS Visual Analytics.  From the right hand pane of the Graph Builder console, select the "Properties" tab:

 

SELECT_PROPERTIES.png

 

From here, you will want to ensure that the Line plot has it's own 'Y axis'.  In order to achieve this, we will want the line chart's axis to be on the RIGHT side of the graph (the default placement is the left side).  Under the "Axes" menu, you will see the "Y axis:" option.  Change this to be "Right."

 

Line_Plot_Axis1.png

 

We now have everything we in place we need to create the "What's The Difference" custom graph.  Go ahead and click "File" -> "Save".  However, when you click "Save," the SAS Custom Graph Builder will give a warning.  The warning essentially informs the user that too many options are still enabled for the graph to be used in SAS Visual Analytics.  One of the options the popup offers is to remove the Lattice Roles.  Fortunately, in order for our custom graph to function properly, the Lattice Roles are not necessary. Hence, go ahead and click: "Remove Lattice Roles and Continue" to save your plot:

 

FINAL_OPTIONS.png

 

Choose a location and name in metadata that you would like to save your custom graph.  I have chosen to name my graph "What's The Difference" and place it in the metadata folder "/Shared Data/Whats The Difference/Reports."

 

Save.png

 

The final step is to use your graph in a report. However, first you will need to ensure that your new custom graph is available in the Visual Analytics Designer - Report Objects.  In order to do this, click the "Show or Hide Objects" button on the "Objects" tab on the left hand pane of the display:

 

SHOW_OR_HIDE.png

 

From the next window, choose "Select Custom":

 

SELECT_CUSTOM.png

 

Navigate to where you saved your custom graph, select it and press "OK."  I saved mine in: "/Shared Data/Whats The Difference/Reports".

 

SELECT_CUSTOM1.png

 

You will now see that your custom graph is available in the "Show or Hide Objects" menu.  You can now press "OK."

 

SELECT_CUSTOM2.png

 

You are now ready to build your report!  

 

Build the report 

For the data, you can use the data from the "2014 National Population Projections: Summary Table"; which is supplied as a csv file in this post. I edited the Population Projection data in the following ways:

  • Because I wanted the deaths metric to be BELOW zero on the Y axis, I made the "Deaths" column negative.
  • Using a simple subtraction formula I created the "Difference" column:
    • Difference = Births - Deaths;

Be sure this data is available in SAS Visual Analytics Designer and follow these steps:

 

  • Place your newly created custom graph on the report canvas
  • Map the data to the graph as shown in the Roles tab on the right of the screenshot below: 
    • You will have to change the "Year" variable to be a "Category"

BUILD_GRAPH.png

 

Finally, to get the correct look, we will SORT the data in the graph by the "Year."  Right-click the "Year" text on the x-axis and choose "Sort" -> "Ascending":

 

SORT.png

 

And you're done!  In my final report, I added a detail table showing the 4 columns used in the plot.  But this is not required.

 

How to make the example work for you 

As mentioned, this example was created in SAS Visual Analytics 7.2. Attached is a SAS package file containing the custom graph template, sample report and data in csv file format. Load the csv file into memory on your SAS Visual Analytics instance and you will be able to import this package if you have access to the SAS Management Console 7.2. Please refer to these instructions.

 

SMC.png

 

If you do not have access, contact your SAS Visual Analytics Administrator. Be sure to select the report and the custom graph.

 

Think you'll give this a try? Tell us about your project, and share you own custom graph examples on the community!

Version history
Last update:
‎05-03-2016 10:12 AM
Updated by:
Contributors

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags