Creating visualizations that compare similar metrics across a categorical variable can be tricky. The report designer needs to show how the values of the two metrics compare, while also allowing the report consumer view those comparisons within an overall group. As I have mentioned in my previous post, I'm a big fan if using butterfly charts for this type of visualization. However, I'm often searching more creative ways to do this type of reporting that might be more useful than butterfly charts.
The good news is the SAS Graph builder is useful for exactly this task. Using the builder, I was able to create the following report:
In the example above I've used the Graph builder to create a chart which displays two metrics within a group.The two metrics I'm comparing are the City Miles Per Gallon (MPG) and Highway MPG. The builder has also allowed me to add a categorical variable, in which I placed the variable Make (or car manufacturer).
The best part is, by using the graph builder this report is very easy to make. In this post, I'll show you how.
Begin by opening the SAS® Graph Builder and dragging a "Schedule Chart" onto the center pane:
From here click the "Options" menu on the left side of your screen. Increase the spacing up to 95%.
From the drop down at the top to the "Options" menu, select "X Axis" and UNCHECK the box next to "Axis label":
Next, from the "Elements" menu on the right add TWO "Bubble Plots" onto the center pane:
With these three graph elements in place, all we have to do is adjust the custom graph's roles.
Click the Roles Menu from the right side of your screen.
Click the dots next to "Shared Role 1" and click "Edit Role":
Change the Role Name to "Category" and press "OK".
Next (still on the "Roles" menu) scroll down to the "Bubble Plot 1" section. Click the three dots next to "Bubble Plot 1 X" and choose "Create shared role" -> "Schedule Chart 1 Start":
At the next screen change the role name to be "Measure1" and press "OK".
Next (still within the "Bubble Plot 1" section) click the three dots next to the "Bubble Plot 1 Size" and choose "Edit Role":
Change the role name to "Measure 1 Size" and press OK.
The next step is to do the same steps on the roles within the "Bubble Plot 2" section. However for this section, create the shared role with "Schedule Chart 1 Finish" and rename it "Measure2". Rename the "Bubble Plot 2 Size" role to "Measure2 Size".
When finished, your roles menu should look like this:
And you're done! You've created a custom graph that has the proper elements to become the data visualization at the top of this post. Save your custom graph and give it a name.
For the data in this post, I used data sourced from the SASHELP data set: 'cars'. I summarized the data by "Make" (or car manufacturer) and sub-setted to cars with a Origin value of "Europe". I titled the output data set "Cars_By_Make". The SAS code to do these simple operations is attached to this post. Import the "CARS_BY_MAKE" on your SAS Visual Analytics instance.
To build the report we will first import the custom graph to a new SAS Visual Analytics report. Add your new custom graph to your reporting canvas.
Then fill out the "Roles" for your custom graph as shown below:
The "Make" variable will be the "Category" (or Task) from our Schedule Chart. MPG City and MPG Highway will be the two metrics we want to compare, respectively. Since we used bubble plots to create the 'ends' of our 'lines,' we have to assign each of them a value. We want these values to be the same. Hence, the data set we are using contains two 'dummy' columns with a value of 1. These two columns are "Bubble1_Size" and "Bubble2_Size". These columns are assigned to (you guessed it) the "Measure1 Size" and "Measure2 Size" roles we created.
And that's it! Add a title to your tab and you're report is complete!
Additionally, I created a custom legend from a text object and placed it under the graph. I also have adjusted the report-level options to acquire the colors in my report above. Both of these final report edits are included in the report's JSON file that is attached to this post.
This example was created in SAS Visual Analytics 8.3. Again, for this post's data, I used data sourced from the SASHELP data set, 'cars,' and did some basic data manipulation to it. The SAS code that performs this data manipulation is attached to this post.
The attachments for this post are:
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.