22
Jun

Advanced ODS Graphics: Vector plots and adjusting point labels

A vector plot draws a line from one point in a graph to another point. In this blog, I will show you how to create short vectors instead of vectors that emanate from the origin. I also show how to modify the positions of the vector labels.

The post Advanced ODS Graphics: Vector plots and adjusting point labels appeared first on Graphically Speaking.

23
Apr

Diagonal tick values

Fitting of long category values on a x-axis is usually a challenge.  With SAS 9.4, the SGPLOT procedure tries to fit the values by first splitting the values at white space to see if the values will fit in the space available.  This normally works for a small number of [...]

The post Diagonal tick values appeared first on Graphically Speaking.

7
Nov

Layers vs annotation

Last week a user asked about BY variable group processing for SGAnnotate with SGPLOT procedure.  The user provided a simple use case for the question (always a good idea) using the sashelp.class data set.  The graph included a display of reference lines for the mean value of height using annotation.  The […]

The post Layers vs annotation appeared first on Graphically Speaking.

1
Nov

Outside-the-box: Directed circle link graphs

One request came in for the previous article on Circle link graph, for the addition of arrow heads to indicate the direction of the flow.  Given that I am using a SERIES plot to render the links, it is relatively easy to add arrow heads to the links as the SERIES […]

The post Outside-the-box: Directed circle link graphs appeared first on Graphically Speaking.

4
Oct

Getting Started with SGPLOT - Part 1 - Scatter Plot

Last week I had the pleasure of presenting my paper "Graphs are Easy with SAS 9.4" at the Boston SAS Users Group meeting.  The turn out was large and over 75% of the audience appeared to be using SAS 9.4 back home.  This was good as my paper was focused on the cool new […]

The post Getting Started with SGPLOT - Part 1 - Scatter Plot appeared first on Graphically Speaking.

10
Jul

Polar Graph - Wind Rose

Last week I posted an article on displaying polar graph using SAS.  When the measured data (R, Theta) are in the polar coordinates as radius and angle, then this data can be easily transformed into the XY space using the simple transform shown below.     x=r*cos(theta * PI / 180);     y=r*sin(theta * PI […]

The post Polar Graph - Wind Rose appeared first on Graphically Speaking.

3
Jul

Polar Graph

There are many situations where it is beneficial to display the data using a polar graph.  Often your data may contain directional information.  Or, the data may be cyclic in nature, with information over time by weeks, or years.  The simple solution is to display the directional or time data […]

The post Polar Graph appeared first on Graphically Speaking.

12
Jun

Infographics: Coin Stack Bar Chart

Often one sees bar charts showing revenues or other related measures by a classifier using a visual of a stack of coins.  Such visuals are not strictly for the purposes of accurate magnitude comparisons, but more for providing an interesting visual to attract the attention of the reader.  In other words […]

The post Infographics: Coin Stack Bar Chart appeared first on Graphically Speaking.

17
Oct

Symbols in SAS 9.4 graphs: unlimited possibilities

Beginning with the first maintenance of SAS 9.4, you have the ability to define your own symbol markers using the SYMBOLCHAR and SYMBOLIMAGE statements. With these statements you can select a Unicode value or you can select an image file that exists on the local file system—making the possibilities for customizing your graphs almost unlimited.

In releases prior to SAS 9.4, the symbol markers supported by the SG procedures are limited to the ones listed in this table:

symbols1

In the examples below, I’ll use a weather chart to show you two different methods for creating custom symbols to suit almost any graph or reporting need. Both techniques begin with standard Unicode values and the new SYMBOLCHAR statement.

Creating the symbols

The first program below includes three SYMBOLCHAR statements. Each SYMBOLCHAR statement contains the name of the symbol and a corresponding Unicode value. Supported image types are GIF, JPEG and PNG files.

Keep in mind that these Unicode values are not SAS specific. A list of valid Unicode values can be found on the Unicode Character Name Index page supplied by The Unicode Consortium. Our data is weather related so I found Unicode values for these symbols:

  • sun    ‘2600’x
  • cloud   ‘2601’x
  • umbrella    ‘2602’x

In this example I want to offset the symbols vertically so they do not overlap the HIGHLOW interpolation. Offsetting is done with the VOFFSET option on the SYMBOLCHAR statement. Here’s how those symbols will be used in the final graph:
symbols2

Producing the graph with Graph Template Language

Once the symbols are defined, I set up a discrete attribute map to assign the color for each symbol based on the values in the data set: Sunny, Cloudy and Showers. Everything is tied together through the DISCRETEATTRVAR statement by associating an attribute variable, SIGN, with the data set variable, FORECAST. Assigning the GROUP option a value of SIGN is the final step.

The AXISTABLE statement, which is a new statement in SAS 9.4, produces the table containing the high and low temperatures inside the axes at the bottom the graph.

data temperatures;
input Day : $9. High Low Forecast $7.;
datalines;
Monday 73 61 Cloudy
Tuesday 76 60 Showers
Wednesday 79 59 Sunny
Thursday 80 60 Sunny
Friday 79 64 Showers
Saturday 73 63 Cloudy
Sunday 75 64 Showers
;
run; 

ods path(prepend) work.templat(update);
proc template;
 define statgraph temp;
 begingraph;
 symbolchar name=cloudy char='2601'x /voffset=.5;
 symbolchar name=sunny char='2600'x / voffset=.5;
 symbolchar name=showers char='2602'x / voffset=.5;

 discreteattrmap name='symbolmap';
   value 'Sunny' / markerattrs=(symbol=sunny color=orange);
   value 'Cloudy' / markerattrs=(symbol=cloudy color=grey);
   value 'Showers' / markerattrs=(symbol=showers color=blue);
enddiscreteattrmap;
discreteattrvar attrvar=sign var=forecast attrmap='symbolmap';

 layout overlay;
    highlowplot x=day low=low high=high / lineattrs=(color=biyg thickness=20pt);
    scatterplot x=day y=high /group=sign markerattrs=(size=25pt) name='weather';
  discretelegend 'weather' / title='Forecast';
    innermargin / align=bottom;
      axistable x=day value=high / valueattrs=(size=9pt weight=bold);
      axistable x=day value=low / valueattrs=(size=9pt weight=bold);
    endinnermargin;
 endlayout;
 endgraph;
 end;

proc sgrender template=temp data=temperatures;
run;

Producing the graph with PROC SGPLOT

This graph can also be produced with PROC SGPLOT using the SYMBOLCHAR statements.  In this instance the attribute map is defined within the data step that creates the data set MYATTRMAP.  The attribute map is referenced with the ATTRID option on the SCATTER statement.  Below is sample code that illustrates the syntax.

data temperatures;
input Day : $9. High Low Forecast $7.;
datalines;
Monday 73 61 Cloudy
Tuesday 76 60 Showers
Wednesday 79 59 Sunny
Thursday 80 60 Sunny
Friday 79 64 Showers
Saturday 73 63 Cloudy
Sunday 75 64 Showers
;
run; 

data myattrmap;
  input id $ value $ markercolor $ markersymbol $;
datalines;
myid Cloudy grey cloud
myid Sunny orange sun
myid Showers blue umbrella
;
run;
proc sgplot data=temperatures dattrmap=myattrmap;
   highlow x=day low=low high=high /lineattrs=(color=biyg thickness=20pt);
   scatter x=day y=high / markerattrs=(size=25pt) attrid=myid group=forecast;
   symbolchar name=Cloud  char='2601'x / voffset=.5;
   symbolchar name=Sun char='2600'x / voffset=.5;
   symbolchar name=Umbrella char='2602'x / voffset=.5;
   xaxistable high / valueattrs=(size=9pt weight=bold)location=inside ;
   xaxistable low / valueattrs=(size=9pt weight=bold) location=inside;
run;

You can download the full programs from the following SAS Samples:

What special symbols can you use in your graphs? Let me know how the new SYMBOLCHAR statement will work for you!

 

tags: Graph Template Language (GTL), Problem Solvers, SAS 9.4, SAS Programmers, SGPLOT procedure
4
Aug

Legend Order in SGPLOT Procedure

This article is by guest contributor Lelia McConnell, SAS Tech Support. Several users have called recently to ask the question, “Can I reorder the legend entries on the bar chart that I created with PROC SPLOT?” Although there is no option that does this directly in PROC SGPLOT, the answer […]
Back to Top