I think bubble plots are one of the best ways to show relationships between variables. However, there are times when the graph's bubbles are positioned so close together it's difficult to determine what their associated data values are. Wouldn't it be nice is if we could get some guidelines which assist in showing the positions of the bubbles in relation to the x and y axes?
Well I have good news! In the SAS Visual Analytics Custom Graph Builder, we can build a bubble plot where we can add these guidelines! Take a look at the graph below which compares the amount of forest area (in square kilometers) in different countries for the years 1990 and 2011. Notice how the faded dashed lines assist the report consumer in seeing the positions of the bubbles' data values on the x and y axes.
Pretty neat! So how did I build this custom graph? Read along and I'll show you!
Start by creating a new custom graph using the graph builder. First, drag these four objects into the canvas in the order shown below:
With these objects in place, we can begin to edit the properties of our custom graph. You can do this by going to the "Options" Menu and using the drop-down menu to select "Vector Plot 2".
From the "Line Color" drop-down select the "Missing data line color" option and deselect the "Arrowheads" checkbox:
Next, from the main "Options" menu drop down select "Vector Plot 1" and made the same edits.
Now still using the main "Options" menu drop down, select "Legends" and choose the "Hide All" option under "Visibility":
We now need to make some edits to the "Legends" sections of our graph. To do this, select the "Discrete Legend" option from the main "Options" menu drop down and deselect all the check boxes:
Next, for the "Bubble Plot 1 Size Legend" and "Bubble Plot 2 Size Legend" sections, deselect the "Show Legend" option:
After making this final change, all options edits for our graph are complete!
The next step is to edit our roles.
Start by going to the Roles menu and looking under the "Shared roles" section. You will see a role called "Shared Role 1". Click the three dots next to it and choose "Edit role":
Rename this role to be "X Axis" and press "OK":
Now we are going to add 3 more roles under the "Shared Roles" section. Add the following roles with the classification set as "Any Classification":
With these new shared roles in place, we can map our graph's object roles to them. For each role in the graph object, select the three dots next to it (as you did for "Shared Role 1" in the previous section) and map them to the following shared roles:
We will also need to add two roles to our second bubble plot. Under the "Bubble Plot 2" section, add the following new roles.
Add a "Group" Role:
Add a "Data Label" role:
Now that these two final roles are in place, the last thing we need to do is share them. You can do this by clicking the three dots next to the newly created role "Bubble Plot Group" and choosing "Create Shared Role with Another Role" -> "Bubble Plot Data Label"
Name this new role "Bubble Plot Group" and keep it's classification as "Category".
And you're done! You've successfully built the custom graph. Save your graph and give it a name.
For this example I needed some data which contained both a category variable and two metrics that could be compared. This Curriculum Pathways Data Depot resource contains information about the forest area (in square kilometers) in different countries for the years 1990 and 2011. It's perfect for our custom graph! It's categorical variable "Country" and numeric variables (_1990 and _2011) are already in the correct format for a bubble plot. The only thing we need to do is add a "Zero" column and do some window dressing to its data labels and formats.
The SAS Code to do this is below:
libname src "<-location of source file->"; data forest_area; set src.forest_area; zero = 0; label _2011 = "2011" _1990 = "1990"; format _2011 comma8. _1990 comma8.; where _2011 ne _1990; run;
And that's it! The forest_area data set is now ready for reporting! All you need to do now is import the data the data to CAS and build the report!
To build the report itself, start by importing the custom graph into a new SAS Visual Analytics report. Add your graph to the canvas by dragging it into the center of the screen.
Next, add the data set 'forest_area' to your report and apply the variable to the appropriate roles shown:
You will notice that there are a lot of bubbles on our graph! You will probably want to filter the data in the graph using a list control. In my example I used a list control to filter to show only the countries: Germany, Ecuador, Chile, Vietnam and Honduras:
Next, you will need to adjust a property at the report level. To do this click the white space at the very top of the page (above the tab for the report) and select the options menu. This will allow you to change report-level properties. From here find the "Data elements style rotation" drop down and select "Rotate All Attributes".
I also edited the order of the colors of my report. If you would like to review these color edits, you import the report using the BubblePlotGuidelines.json file located in GitHub repository which is liked to this article.
After making this report level edit, you will see the guidelines are dashed lines, which is the desired effect as they do not represent actual data values, but rather are present to assist the report consumer in understanding the graph.
And that's it! You've rebuilt the graph:
This example was created in SAS Visual Analytics 8.3.1. Again, for this post's data, I used the Curriculum Pathways Data Depot resource which contains information about the forest area (in square kilometers) in different countries for the years 1990 and 2011.
On Github, you will find the following support files for this article:
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.