BookmarkSubscribeRSS Feed

3 steps to label specific data points in SAS Visual Analytics custom graphs

Started ‎10-22-2018 by
Modified ‎10-22-2018 by
Views 5,886

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:


label data points image example..png



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!


Step 1: Build a custom graph


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".

Press "OK".




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. 


Step 2: Prepare your data 


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!


Step 3: Build the 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."


How to make this example work for you

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:

  • The code to create the report ready data -
  • A JSON file containing the custom graph - LabelYourWork_CustomGraph.json
  • A JSON file containing the completed report - Label_Your_Work.json

Import the data on your SAS Visual Analytics instance.  Import the report via the "Import via GUI" section of these instructions.  


Great post!


This is a really nice way to guide users and point out importent happenings in the data.

I think this can be applied to many trend graphs where underlaying logic marks specific data points and point the users directly there 🙂



Thanks Fredrik!


The good news is, using the Graph Builder you can add the same "Data Label" role to other objects such as Bubble Plots, Scatter Plots and Schedule Charts!

Version history
Last update:
‎10-22-2018 09:25 AM
Updated by:



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. 

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