Curve labels in series plots can be positioned inside or outside the graph. Date variables can be specified as TYPE=LINEAR with a date format or more commonly as TYPE=DATE. Sometimes external curve labels might appear below or above the graph, particularly with TYPE=DATE axes. This blog shows you ways to move them to the right of the graph.
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.
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 [...]
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 […]
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 […]
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.
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 […]
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 […]
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 […]
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:
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:
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:
- Sample 54314: Customize your symbols with the SYMBOLCHAR statement in the Graph Template Language (GTL)
- Sample 54315: Customize your symbols with the SYMBOLCHAR statement in PROC SGPLOT
What special symbols can you use in your graphs? Let me know how the new SYMBOLCHAR statement will work for you!