Animated Graphs for a New Era

Animated Graphs for a New Era

Mitchell Collins, Cal Poly, San Luis Obispo, CA

ABSTRACT

As someone studying statistics in the data science era, more and more emphasis is put on illustrious graphs. Data is no longer displayed with a black and white boxplot. Using SAS? macros and the Statistical Graphics procedure, you can animate graphs to turn an outdated two variable graph into a graph in motion that shows not only a relationship between factors but also a change over time. An even simpler approach for bubble plots is to use a function in JMP to create colorful moving plots that would typically require many lines of code, with just a few clicks of the mouse.

INTRODUCTION

This paper will cover three methods for creating animated graphs with SAS products. First, we will cover how to use SAS MACRO and the Statistical Graphics procedure to create moving graphs. Second, we will examine how to use ODS Graphics Designer to design more illustrious graphs, which can then be used to make animated graphs. Lastly, we will demonstrate how to use JMP's bubble plot option to create moving graphs after only a few clicks of the mouse.

BASICS OF ANIMATED SAS GRAPHS

Making an animated plot in SAS begins with creating a macro. In the macro, we include code that will create the graph with a macro parameter that subsets the data you want for each individual graph. Once you complete the macro, you will also want to include certain options and open up the ODS Printer destination to create the file.

options printerpath=gif animation=start animduration= animloop= noanimoverlay

nodate nonumber;

ods printer file="";

Command

Purpose

printerpath=gif

Initiates creation of a .gif file

animation=start

Begins animation

animduration=

Gives the duration of each slide in seconds

animloop=

Asks whether or not the gif should be played on loop (yes, no, or n are possible options)

noanimoverlay

Tells SAS each graph should replace the old one in the .gif

nodate

Prevents display of the date value

nonumber

Prevents display of the number of graph

ods printer file="" Table 1. Command Explanation

Opens ODS Printer and states file location

After these two lines of code are included, the macro calls are placed in the order in which the graphs should appear in the graph. The graph is completed with the following code and the resulting gif file can be found in the location specified:

options printerpath=gif animation=stop; ods printer close;

EXAMPLE

In this example, we have a dataset that includes yards and touchdowns (TDs) of starting quarterbacks (QBs) from 1935-2015 in the NFL. We want to display this for every year rather than a single year or display only a few famous QBs. We start by creating a macro where in the data step we subset by a macro variable called year and then follow with the Statistical Graph Procedure:

%macro football(year); data football1; set football;

1

Animated Graphs for a New Era, continued

if year=&year; ypg=yds/g; tdpg=td/g; run; proc sgplot data=football1; refline 342.3125 / axis=x label="Record 5477 Yard Season"; refline 3.4375 / label="Record 55 TD Season"; scatter x=ypg y=tdpg; xaxis max=350 min=0 label="Yards per Game"; yaxis max=3.5 min=0 label="TDs per Game"; title "It's a Passing League"; run; %mend;

After the macro, the options and ODS Printer statements stated above are included. Next the macro is called for each year: %football(1935); %football(1936); ... %football(2015);

This produces the desired gif showing the history of NFL passing from 1935 to 2015, by year. The full code of the graph can be found in the appendix.

Figure 1. Output for the macro call %football(1959)

ODS GRAPHICS DESIGNER

In order to make more illustrious moving graphs we can use ODS Graphics Designer. ODS Graphics Designer can be opened under SAS tools and is a much easier way to make graphs if you're not a SAS coding expert. After opening ODS Graphics Designer you can choose to make a plethora of graph the range from a step plot to a contour plot. ODS Graphics Designer allows you the opportunity to specify key details that typically would require a higher level of SAS template programming or an hour spent on research.

2

Animated Graphs for a New Era, continued

Display 1. Starting Screen of ODS Graphics Designer After creating the graph, the code for the graph can be viewed by going to view and then selecting code.

This code can be copied and pasted into the SAS program editor. The code should be placed in the macro right after including the code that subsets the data. After creating the macro the steps listed in the first part of the paper can be followed to make a .gif out of the macro.

Display 2. Code produced after making a graph with ODS Graphics Designer.

EXAMPLE

For this example we explore data on political affiliation of the United States Senate from 1790-2015. The data from each session of Congress is displayed, one at a time, in order to get a better visual of the change throughout history. Using the easy customizability that is found in ODS Graphics Designer, there were no issues in adding reference lines for percentages of interest onto the graph (0.5 for majority, 0.6 for preventing filibusters, and 0.67 for writing constitutional amendments).

3

Animated Graphs for a New Era, continued

Display 3. Entering Tick Marks of Interest in ODS Graphics Designer After obtaining the code from the graph we created a macro by combining this code to subset to each graph

to all previous congressional sessions. data senate; set senate1; if congress ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download