SAS/GRAPH Colors and Images |
SAS/GRAPH enables you to display images as part of your graph. You can place an image in the background area of a graph, in the backplane of graphs that support frames, or on the bars of two-dimensional bar charts. You can also apply images at specified graph-coordinate positions using the Annotate facility or the DATA Step Graphics Interface (DSGI).
The images you add to your graphs can be SAS files or external files, in a range of image formats.
Image File Types Supported by SAS/GRAPH |
For displaying images in your graphs, SAS/GRAPH supports the image file types shown in the following table.
Displaying an Image in a Graph Background |
To place an image on the graph background, use the IBACK= option in a GOPTIONS statement. Specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file as follows:
goptions iback="external-image-file" | fileref;
For example, the following program creates a pie chart with a background image:
goptions reset=all htitle=1.25 colors=(cx7c95ca cxde7d6f cx66ada0 cxb689cd cxa9865b cxbabc5c) iback="external-image-file"; title "Projected Automobile Sales"; data sales; input Month Amount; informat month monyy.; datalines; jan08 200 feb08 145 mar08 220 apr08 180 may08 155 jun08 250 ; proc sort; by month; proc gchart; format month monname8.; pie month / discrete freq=amount value=inside noheading coutline=black; run; quit;
Because the default value for the IMAGESTYLE= graphics option is TILE, the image is copied as many times as needed to fill the background area.
You can specify IMAGESTYLE=FIT in the GOPTIONS statement to stretch the image so that a single image fits within the entire background area.
Displaying an Image in Graph Frame |
Procedure action statements that support the IFRAME= support frames, which are the backplanes behind the graphs. The backplane is the area within the graph axes. To place an image on the backplane of a graph, specify the IFRAME= option in the procedure action statement that generates the graph. On the IFRAME= option, specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file:
iframe=fileref | "external-image-file";
For example, the following program creates a vertical bar chart and adds an image to the graph frame:
goptions reset=all htitle=1.25 colors=(yellow cxde7d6f); title "Projected Automobile Sales"; data sales; input Month Amount; informat month monyy.; datalines; jan08 200 feb08 145 mar08 220 apr08 180 may08 155 jun08 250 ; proc sort; by month; proc gchart; format month monname8.; vbar month / discrete freq=amount inside=freq coutline=black iframe="external-image-file"; run; quit;
Because the default value for the IMAGESTYLE= graphics option is TILE, the image is copied as many times as needed to fill the frame area.
You can specify IMAGESTYLE=FIT in the GOPTIONS statement to stretch the image so that a single image fits within the entire frame area.
Displaying Images on Data Elements |
You can place images on the bars in two-dimensional bar charts generated by the GCHART HBAR or VBAR statements. You can also place images on the bars in three-dimensional bar charts if you are using the ACTIVEX device.
On the IMAGE= option of the PATTERN statement, specify either the path to the image file in quotation marks or a fileref that has been defined to point to the image file.
pattern image=fileref | "external-image-file";
By default, the image is tiled on the bar, which means that the image is copied as many times as needed to fill each bar. Specify IMAGESTYLE=FIT in the PATTERN statement to stretch the image as needed to fill each bar.
pattern image="external-image-file" imagestyle=fit;
To tile subsequent images, reset the PATTERN statement or by specify IMAGESTYLE=TILE.
Note: Images are supported on bar charts generated by the HBAR and VBAR statements. If an image is specified on a PATTERN statement that is used with another type of chart, then the PATTERN statement is ignored and default pattern rotation is affected. If you submit a PIE statement when an image has been specified in the PATTERN= option, the default fill pattern is used for the pie slices. Each pie slice displays the same fill pattern.
The following example places an image on the bars of a vertical bar chart:
goptions reset=all htitle=1.25 colors=(yellow cxde7d6f); title "Projected Automobile Sales"; data sales; input Month Amount; informat month monyy.; datalines; jan08 200 feb08 145 mar08 220 apr08 180 may08 155 jun08 250 ; proc sort; by month; pattern1 image="external-image-file"; proc gchart; format month monname8.; vbar month / discrete freq=amount inside=freq coutline=black; run; quit;
The image is tiled to fill each bar.
If the PATTERN IMAGESTYLE=FIT option is used, the image is stretched to fill each bar.
pattern=fileref | "external-image-file" imagestyle=fit;
Displaying Images Using Annotate |
The Annotate facility enables you to display an image at the coordinate location that you specify with the X and Y variables. To display an image, do the following:
Specify the image file in quotation marks on the IMGPATH variable.
Set the image coordinates with the X and Y variables.
Specify the IMAGE function.
goptions reset=all border htitle=1.25 hsize=5.5in vsize=4.2in; data my_anno; length function $8; xsys="3"; ysys="3"; when="a"; function="move"; x=55; y=55; output; function="image"; style="fit"; imgpath="external-image-file"; x=x+15; y=y+18; output; run; title1 "GMAP with Annotated Image"; proc gmap data=maps.us map=maps.us anno=my_anno; id state; choro state/ levels=1 nolegend statistic=freq; run; quit;
The style="fit" variable on the IMAGE function stretches the image as needed to fill the area.
To tile the image to fill the area, set the STYLE variable equal to "tile" .Displaying Images using DSGI |
Using the DATA Step Graphics Interface (DSGI), you can display an image in a designated position. To display an image, specify the file specification for the image file in quotation marks on the GDRAW('IMAGE',...) function.
This code displays the image in the screen coordinates (20, 20) to (40, 40). The last parameter, FIT, indicates how to display the image.
rc=gdraw("image", "external-image-file", 20, 20, 40, 40, "fit");
Image File Types Supported by SAS/GRAPH shows the supported image file formats.
goptions reset=all ftext="Albany AMT/bold" htitle=1.25 hsize=5.5in vsize=4.2in; title "DSGI with Image"; data image; rc=ginit(); rc=graph("clear"); rc=gdraw("image","external-image-file", 5, 5, 90, 90,"tile"); rc=graph("update"); rc=gterm(); run; quit;
If you specify the TILE keyword for the GDRAW('IMAGE',...) function, the image is copied as many times as needed to fill the specified area.
rc=gdraw("image","external-image-file", 5, 5, 90, 90,"tile");
If you specify the FIT keyword for the GDRAW('IMAGE',...) function, the image is stretched to fit within the entire area.
rc=gdraw("image","external-image-file", 5, 5, 90, 90,"fit");
Disabling and Enabling Image Output |
The NOIMAGEPRINT graphics option disables image output without removing code from your SAS/GRAPH program. It is useful for printing output without images.
goptions noimageprint;
To enable image output, reset the GOPTIONS statement or specify the IMAGEPRINT graphics option.
goptions imageprint;
Copyright © 2010 by SAS Institute Inc., Cary, NC, USA. All rights reserved.