Have you ever created a report in SAS Visual Analytics and needed to add labels on specific data values? This is a common need when creating infographics, where you need to quickly get information across to the report consumer. Here's an example:
Notice how the line plot has a data value for each year, however the report author has placed labels on the data values for 1997, 1999 and 2003. By doing this, the data visualization is much more useful as the report consumer can quickly see how the rest of the data values compare to the values at these three specifically-labeled years.
In SAS Visual Analytics 8.3 you can add labels to data points using the graph builder. You can easily create a visualization like this:
Notice that the line plot has a value for each movie for each year. However I have added labels on only the three movies that made the most money. This way we can quickly highlight these three values for the report consumer. Pretty neat! In this post, I'll outline the three steps to add these types of labels to recreate the report above. Let's get started!
As I mentioned in my previous post, SAS Visual Analytics 8.3 brings with it the return of the SAS® Graph Builder. This is great news for report developers who need to create custom graphics like one referenced above. So in order to recreate the line plot with specific labels, we will need to create a custom graph in Visual Analytics 8.3.
We will start with a "Series Plot" in the custom graph builder:
With the series plot selected, go to the "Roles" menu from the right side of your screen and click "Add":
In the "Add Role" menu, select "Data Label" for Role Type and Name the role "Data Label".
We have now successfully added a role which will print the label values on the data points on our series plot! However one of the cooler parts of the example graph we are recreating are the vertical lines that go from the base of the x-axis to the values at years 1997, 1999 and 2003. In order to do this, we will need to add a Needle Plot to our current custom graph. To do this, select the "Needle Plot" from the Graph Elements menu on the left and drag it on top of the series plot:
With the needle plot in place, go back to the "Roles" menu. Let's edit the newly created "Shared Role":
Let's name it "X Axis":
Next, from the menu on the right select "Options".
Then from the drop down, select "Series Plot 1":
At the next screen, click the checkbox for "Markers":
And you've done it! Save your custom graph and give it a name.
For this post's data, I'll be using a data set which contains the top 100 movies based on cumulative domestic and international box office results as of April 2017. This data can be downloaded from this Curriculum Pathways Data Depot resource.
Initially the data looks like this:
In order to get our graph to display correctly, we will need to do some very basic data preparation. Principally, we will need to create two new columns in the data. These columns are "label" and "label_val," and we want values for these columns to appear only for the three highest grossing movies in our data. These would be the movies ranked 1, 2 & 3.
Hence the following SAS code will do that:
/* create the "Label" Column */ if rank le 3 then label=scan(trim(movie),1,':'); else label=""; /* create the "Label" Column */ if rank le 3 then label_val=domestic; else label_val=.;
Our ETL will also drop unnecessary columns as well as create the variable "years" as a sasdate.
The final output data set is below:
Armed this 'report-ready data set' and our new custom graph, we are now ready to build our report!
All that's left is for us is to import the custom graph to a Visual Analytics report.
After we have added the custom graph to the reporting pane we can apply the roles as shown below:
This produces the following graph:
And that's it! By using the "Data Label" role on the series plot in conjunction with the Needle Plot overlaid, we have created our time series plot and LABELED the specific values we wanted to point out (the top three highest grossing movies). I also selected a black color for my series plot as well as titled the report's tab "Top Movies Based on Cumulative Domestic Box Office Results."
This example was created in SAS Visual Analytics 8.3. Again, for this post's data, I used a data set which contains the top 100 movies based on cumulative domestic and international box office results as of April 2017. This data can be downloaded from this Curriculum Pathways Data Depot resource.
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.