Managing Your Graphics With ODS |
Introduction |
You can use the ODS GRAPHICS statement options to control many aspects of your graphics. The settings you specify remain in effect for all graphics until you change or reset these settings with another ODS GRAPHICS statement. When you use the GTL language or SAS/GRAPH Statistical Graphics procedures, the ODS GRAPHICS is always ON. However, you can use the ODS GRAPHICS statement to control the following:
the size of the image
the type and name of the image created
whether features such as data tips, scaling, and anti-aliasing are used
The basic syntax for the ODS GRAPHICS statement is:
ODS GRAPHICS < OFF | ON> </ option(s)>; |
For a table of options for the ODS GRAPHICS statement, see ODS GRAPHICS Statement Options.
The following program uses the ODS GRAPHICS statement to illustrate several techniques for controlling your graphics. These techniques are discussed in the following sections:
Controlling Graphics with the ODS GRAPHICS Statement 1 ods graphics on / 2 width=3.25in 3 imagefmt=gif 4 imagemap=on 5 imagename="MyBoxplot" 6 border=off; ods html file="Boxplot-Body.html" style=journal gpath="your-file-path"; proc sgplot data=sashelp.heart; title "Cholesterol Distribution by Weight Class"; hbox cholesterol / category=weight_status; run; ods html close; 7 ods graphics on / reset=all imagename="MyResetplot"; ods html file="BoxPlotReset-Body.html" style=journal gpath="your-file-path"; proc sgplot data=laborforce; hbox unemplrate / category=state datalabel=year; run; ods html close;
3.25 Inch Graph with Data Tips and No Border
Graph with Options Set Back to Defaults
The numbers in the following sections correspond to numbers in the program above.
Controlling the Size of Your Graph |
The output size of a graph is determined by the following:
For SGRENDER output, the design size for the graph as specified in the StatGraph template. The default sizes defined in the registry are:
Default design width=640px
Default design height=480px
Default aspect ratio is 4/3
For SGPLOT, SGPANEL, or SGSCATTER output, the preceding default sizes are used.
DPI settings for the output destinations, as specified by the IMAGE_DPI= or DPI= options
User specified settings for width and height, as specified by the WIDTH= option and the HEIGHT= option for the ODS GRAPHICS statement.
When modifying the size of your graph, it is important to take into consideration the image scaling and aspect ratio, as well as the width and height of the graph. For example, rendering a graph to the Listing destination at the default design size and default DPI of 100, produces a graph that is 640 by 480 pixels. If the same graph is rendered to the RTF destination, which has a default DPI of 200, the graph size is 1280 by 960 pixels. In both cases, when this image is embedded into an RTF document, its size in the document is 6.4 in. by 4.8 in, since DPI data is included in the image. The aspect ratio of the graph is retained.
When the DPI of a graph is changed due to a change in output destination or user specification, the graph is scaled using a baseline DPI of 100. All graphical elements such as marker size, line thickness, font sizes, and gutters are also scaled.
You can control the output size of a graph by specifying the WIDTH= or HEIGHT= options in the ODS GRAPHICS statement. In the ODS GRAPHICS statement below, taken from Controlling Graphics with the ODS GRAPHICS Statement, the WIDTH= option () changes the width of the graph to 3.25 inches:
ods graphics on / 2 width=3.25in imagefmt=gif imagemap=on imagename="MyBoxplot" border=off;
Although you can use the ODS GRAPHICS statement to specify the WIDTH= option, the HEIGHT= option, or both, it is highly recommended that only one of these options be specified at a time. Using one option at a time ensures that the design aspect ratio of the graph is maintained.
When only width is specified, SAS uses the design aspect ratio of the graph to compute the appropriate height. Retaining the design aspect ratio of the graph is important in many cases as the graph might have a specific layout. For example, a plot that has multiple columns, or that has a statistics table on the side needs a wide aspect ratio. Changing the aspect ratio for this plot by specifying both width and height might produce unpredictable results.
When the size of a graph is changed by specifying the WIDTH= option in the ODS GRAPHICS statement, the output size of the graph is computed based on the new size, and the active DPI, using a baseline of DPI of 100. All graphical elements such as marker size, line thickness, font size, and gutters are scaled using a non-linear scale. This is done to prevent rapid shrinking or growth of the fonts and markers.
Scaling of graph elements for change in graph size can be disabled by the ODS GRAPHICS statement options NOSCALE or SCALE=OFF. By default, scaling is on. Specifying NOSCALE or SCALE=OFF prevents the scaling of the graph elements. If you want to shrink your graph and keep the default sizes for fonts, use the NOSCALE or SCALE=ON option in the ODS GRAPHICS statement.
It is often useful to produce a graph that fits in one column of a two column page. In this case, the column size might be 3.25 inches wide. You can place a default output image, which is 640 by 480 pixels, in this space, but then all graphical elements scale down. This results in small markers and unreadable small fonts.
In this case, it is useful to render the graph to the exact size required, and specify the correct DPI. In the situation above, you would specify a width of 3.25 inches and use the IMAGE_DPI= destination statement option to specify a DPI of 200. Then, the graph produced can be placed in the 3.25" wide column and the fonts and markers are readable.
Note: To get exactly the specified font sizes, use the NOSCALE option in the ODS GRAPHICS statement.
Adding Data Tips and Other Features |
With ODS GRAPHICS statement options you can control different features of your graphs, such as borders and data tips. In the ODS GRAPHICS statement below, taken from Controlling Graphics with the ODS GRAPHICS Statement, the BORDER=OFF option () specifies that there be no border around the graph and the IMAGEMAP=ON () option enables the generation of data tips and any drill downs:
ods graphics on / width=3.25in imagefmt=gif 4 imagemap=on imagename="MyBoxplot" 6 border=off;
When viewing HTML output, data tips appear when you move a mouse over certain features of the graph. Data tips and URL drill down functionality are available only for the HTML destination. You can also specify the maximum number of distinct mouse over areas allowed before data tips are disabled by using the TOOLTIPMAX= option. There are many other ODS GRAPHICS options you can use to control other aspects of your graphics. See ODS GRAPHICS Statement Options for a table of ODS GRAPHICS statement options.
Resetting ODS GRAPHICS Options |
You can specify the RESET option to change the values for these options back to their defaults. In Controlling Graphics with the ODS GRAPHICS Statement, the second ODS GRAPHICS statement () uses the RESET=ALL option to set all options back to their defaults for a new graph:
7 ods graphics on / reset=all imagename="MyResetplot";
You can also reset ODS GRAPHICS options individually. For a list of values valid for the RESET= option, see ODS GRAPHICS Statement Options.
Note: When you specify the RESET= option, ensure that it is the first option specified in the ODS GRAPHICS statement. Otherwise, you might reset some of other options in the statement.
For the complete documentation on all ODS GRAPHICS statement options, see ODS GRAPHICS Statement Options.
Accessing Graphs as Separate Files |
ODS enables you to change the ODS destination where you are sending your output to result in different output formats such as RTF or PDF. There might also be times when you want to access your graphs as individual image files.
The default image file type is determined by the ODS destination. You can use the IMAGEFMT= option to specify a different image file format. The type of image allowed is dependent on the destination you have specified. See Supported Image File Types for Output Destinations for a table of ODS destinations and their valid file types.
You can also specify names for your graphics image files and the directory in which you want to save them. The IMAGENAME= option specifies the base image filename and the GPATH= option specifies a directory for your images.
In the ODS GRAPHICS statement below, taken from Controlling Graphics with the ODS GRAPHICS Statement, the IMAGEFMT= option () specifies that the file type is a GIF, and the IMAGENAME= option () specifies that the name of the image is "MyBoxplot":
ods graphics on / width=3.25in 3 imagefmt=gif imagemap=on 5 imagename="MyBoxplot" border=off;
The resulting filename for the image created is MyBoxplot.GIF. If there is more then one image, they are named MyBoxplot1.GIF, MyBoxplot2.GIF, and so on.
The second ODS GRAPHICS statement () specifies the filename "MyBoxplot" for the second image. However, because the RESET=ALL option is used, the file type is PNG, which is the default file type for the HTML destination:
7 ods graphics on / reset=all imagename="MyBoxplot";
For the ODS destinations that generate graphic image files, these image files are saved by default into the SAS current working directory. You can use the GPATH= option to specify a directory for saving your graphics image files. For example, in Controlling Graphics with the ODS GRAPHICS Statement the GPATH= option on both of the ODS HTML statements specifies that all images be saved in the directory C:\myfiles\images.
For more information about ODS destinations, see SAS Output Delivery System: User's Guide.
The following table lists all of the supported image file types for ODS output destinations.
ODS GRAPHICS Statement Options |
The following options can be used with the ODS GRAPHICS statement.
Task | Option | |
---|---|---|
Specify whether anti-aliasing is applied to the rendering of the line and markers in any graph. |
ANTIALIAS= | ANTIALIAS | NOANTIALIAS |
|
Specify the maximum number of markers or lines to be anti-aliased before anti-aliasing is disabled. |
ANTIALIASMAX= |
|
Specify whether to draw a border around each graph. |
BORDER= | BORDER | NOBORDER |
|
Specify the maximum number of discrete values to be shown in any graph. |
DISCRETEMAX= |
|
Specify the maximum number of group values to be shown in any graph. |
GROUPMAX= |
|
Specify the height of any graph. |
HEIGHT= |
|
Specify the image format used to generate image files. |
IMAGEFMT= |
|
Specify whether data tips are generated. |
IMAGEMAP=| IMAGEMAP | NOIMAGEMAP |
|
Specify the base image filename. |
IMAGENAME= |
|
Specify the maximum number of labeled areas before labeling is disabled. |
LABELMAX= |
|
Specify an integer that is interpreted as the maximum percentage of the overall graphics area that a legend can occupy. |
MAXLEGENDAREA= |
|
Specify the maximum number of cells in a graph panel where the number of cells is determined dynamically by classification variables. |
PANELCELLMAX= |
|
Reset one or more ODS GRAPHICS options to its default. |
RESET | RESET= |
|
Specify whether the content of any graph is scaled proportionally. |
NOSCALE | SCALE | SCALE= |
|
Specify the maximum number of distinct mouse--over areas allowed before data tips are disabled. |
TIPMAX= |
|
Specify the width of any graph. |
WIDTH= |
specifies whether anti-aliasing is applied to the rendering of the line and markers in any graph. Anti-aliasing smooths the appearance of diagonal lines and some markers. Text displayed in the graph is always anti-aliased. For graphical displays that plot large numbers of points it is recommended that ANTIALIAS=OFF be specified for performance considerations.
specifies whether anti-aliasing is applied to the rendering of the line and markers in the graph.
OFF |
does not smooth jagged edges of components other than text in the graph.
| ||
ON |
smooths jagged edges of all components in the graph.
|
smooths jagged edges of all components in the graph.
does not smooth jagged edges of components other than text in the graph.
Default: | ON |
Restriction: | If the number of markers or curve points in the plot exceeds the number specified by the ANTIALIASMAX= option, then the ANTIALIAS option is turned off, even if you specify the option ANTIALIAS=ON or ANTIALIAS. |
specifies the maximum number of markers or lines to be anti-aliased before anti-aliasing is disabled. For example, if there are more than 400 scatter point markers to be anti-aliased and ANTIALIASMAX=400, then no markers are anti-aliased.
specifies a positive integer.
Default: | 600 |
specifies whether to draw a border around any graph.
specifies whether to draw the graph with a border on the outermost layout.
specifies to draw a border around the graph.
Alias: | YES |
specifies not to draw a border around the graph.
Alias: | NO |
specifies to draw a border around the graph.
specifies not to draw a border around any graph.
Default: | BORDER or BORDER=ON |
specifies the maximum number of discrete values to be shown in any graph. Bar charts and box plots are examples of affected plot types. Scatter plots and other plot types might be affected if the data to be plotted is discrete or the axis is discrete.
specifies a positive integer.
Default: | 1000 |
Tip: | Some plot layers might be unaffected by the DISCRETEMAX= option, and those layers are still rendered. If all layers are affected, then a blank graph is rendered. |
Tip: | If the value specified by the DISCRETEMAX= option is exceeded by any plot layer in the graph, that layer is not drawn and a warning message is issued. |
specifies the maximum number of group values to be shown in any graph. Any graph that supports the GROUP= option is affected.
specifies a positive integer.
Default: | 1000 |
Tip: | If the value specified by the GROUPMAX= option is exceeded by any plot layer in the graph, that layer is rendered ignoring the GROUP= option and a warning message is issued. |
specifies the height of any graph.
is a nonnegative number.
See: | dimension |
Default: | The value of the SAS registry entry "ODS > STATISTICAL GRAPHICS > Design Height" or the value of the DesignHeight= option in a STATGRAPH template. Typically, the value is 480px. |
specifies the image format to be used. If the image format is not valid for the active output destination, the format is automatically changed to the default image format for that destination.
is the image format to be generated. See Supported Image File Types for Output Destinations.
uses the best quality static image format for the active output destination. This is the default.
Default: | STATIC |
controls data tips generation. Data tips are pieces of explanatory text that appear when you mouse-over the data portions of a graph contained in an HTML page.
controls data tips generation.
OFF |
specifies not to generate data tips.
| ||
ON |
specifies to generate data tips.
|
specifies to generate data tips.
specifies not to generate data tips.
Default: | OFF or NOIMAGEMAP |
Restriction: | This option applies only when the ODS HTML destination is used. |
specifies the base image filename.
If more than one image is generated, each is assigned filename as a base name followed by a number in order to create unique names. This numbering can be reset with the RESET=INDEX option. Path information (if needed) can be set with the GPATH= option in the ODS destination statement. The default path is the current output directory. A file extension for filename is automatically generated based on the IMAGEFMT= option.
Requirement: | You must enclose filename in quotation marks. |
Restriction: | filename must be a single name. It must not include any path specification or image-format name extension. |
Default: | The name of the output object. |
specifies the maximum number of labeled areas before labeling is disabled. For example, if there are more than 50 points to be labeled and LABELMAX=50, then no points are labeled.
specifies a positive integer.
Default: | 200 |
specifies an integer that is interpreted as the maximum percentage of the overall graphics area that a legend can occupy.
specifies a positive integer.
Default: | 20 |
Tip: | To turn off the legend, specify MAXLEGENDAREA=0. No warning is issued when the legend is turned off in this way. |
specifies the maximum number of cells in a graph panel where the number of cells is determined dynamically by classification variables.
specifies a positive integer.
Default: | 10000 |
Tip: | If the value specified by the PANELCELLMAX= option is exceeded by either of these layouts, an empty graph is rendered and a warning message is issued. |
resets one or more ODS GRAPHICS options to its default.
resets all of the options to their defaults.
resets one of the following to its default:
resets all of the reset-options to their defaults.
resets the ANTIALIAS option to its default.
resets the ANTIALIASMAX option to its default.
resets the BORDER= option to its default.
resets the IMAGEMAP= option to its default.
resets the index counter that is appended to static image files.
resets the HEIGHT= option to its default.
resets the IMAGEMAP= option to its default.
Note: Not all output destinations support this feature.
resets the LABELMAX= option to its default.
resets the SCALE= option to its default.
resets the TIPMAX= option to its default.
resets the WIDTH= option to its default.
specifies whether the content of any graph is scaled proportionally.
does not scale the components of graph proportionally.
scales the components of graph proportionally.
specifies whether the content of the graph is scaled proportionally.
OFF |
does not scale the components of graph proportionally.
| ||||
ON |
scales the components of graph proportionally.
|
Default: | ON or SCALE |
specifies the maximum number of distinct mouse-over areas allowed before data tips are disabled. For example, if there are more than 400 points in a scatter plot, and TIPMAX=400, then no data tips appear.
specifies a positive integer.
Default: | 500 |
specifies the width of any graph.
is a nonnegative number.
Default: | The value of the SAS registry entry "ODS > STATISTICAL GRAPHICS > Design Width" or the value of the DesignWidth= option in a STATGRAPH template. Typically, this value is 640px. |
See: | dimension |
dimension |
is a nonnegative number, which can be followed by one of these units of measure:
|
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.