Statistical Graphics Using ODS

Attribute Priority and Overriding How Groups Are Distinguished

ODS styles have an ATTRPRIORITY= option with the specification ATTRPRIORITY='Color' or ATTRPRIORITY='None'. The ODS GRAPHICS statement has an ATTRPRIORITY= option with the specification ATTRPRIORITY=COLOR or ATTRPRIORITY=NONE. The default attribute priority for the style option is 'None'. The default attribute priority for the ODS GRAPHICS statement option is the attribute priority from the style. The ODS styles that distinguish groups by color alone are ATTRPRIORITY='Color' styles. The ODS styles that distinguish groups by varying colors, markers, and line patterns are ATTRPRIORITY='None' styles. The ATTRPRIORITY='Color' styles include HTMLBLUE, PEARL, PEARLJ, and SAPPHIRE. Most other styles are ATTRPRIORITY='None' styles. (For more information about styles and attribute priority, see the section ODS Styles.) You can override the ATTRPRIORITY= option in all styles by specifying one of the following statements:

ods graphics on / attrpriority=color;
ods graphics on / attrpriority=none;

You can reset the default ODS Graphics options as follows:

ods graphics on / reset;

The following steps illustrate three ways to make graphs and create the graphs in Figure 15:

ods graphics on / attrpriority=color;
proc sgplot data=sashelp.class;
   title 'Attribute Priority = Color';
   reg y=weight x=height / group=sex;
   keylegend / location=inside position=topleft across=1;
run;

ods graphics on / attrpriority=none;
proc sgplot data=sashelp.class;
   title 'Attribute Priority = None';
   reg y=weight x=height / group=sex;
   keylegend / location=inside position=topleft across=1;
run;

proc sgplot data=sashelp.class;
   title 'Solid Lines but Varying Markers';
   styleattrs datalinepatterns=(solid);
   reg y=weight x=height / group=sex;
   keylegend / location=inside position=topleft across=1;
run;
ods graphics on / reset;

Figure 15: Attribute Priority

Attribute Priority


attrsolb

attrsolc

The settings that are shown in the last graph, which has solid lines but varying markers, often work well when there are multiple groups. You might not need to vary the line style, but varying the markers makes it easier to distinguish the points. For example, it is easy to see in the last two graphs that one point corresponds to both a male and a female point.

You can modify the attribute priority in any style by specifying the ATTRPRIORITY= option, as in the following examples:

proc template;
   define style styles.Default;
      parent = styles.default;
      style Graph from Graph / attrpriority = "Color";
   end;
   define style styles.HTMLBlue;
      parent = styles.HTMLBlue;
      style Graph from Graph / attrpriority = "None";
   end;
run;

You can delete the modified style templates as follows:

proc template;
   delete styles.Default  / store=sasuser.templat;
   delete styles.HTMLBlue / store=sasuser.templat;
run;

In the statistical graphics (SG) procedures, you can override the style attributes and modify how you distinguish groups by using the STYLEATTRS statement:

ods graphics on / attrpriority=none;

proc sgplot data=sashelp.iris;
   title 'Fisher (1936) Iris Data';
   styleattrs datasymbols=(circlefilled squarefilled starfilled)
              datacontrastcolors=(red green blue);
   scatter x=petallength y=petalwidth / group=species markerattrs=(size=5px);
run;

ods graphics / reset;

The results are displayed in Figure 16.

Figure 16: Iris Data

Iris Data


Note: Specifying more than one value in a STYLEATTRS statement option list works only when the attribute priority is 'None'. The STYLEATTRS statement overrides the default style elements, but it does not force the style elements GraphData2, GraphData3, and so on to be used.

The STYLEATTRS statement options are as follows:

DATACOLORS=(color-list)

specifies the fill colors. You can specify common color names or values of the form CXrrggbb, where the last six characters specify RGB (red, green, blue) values on the hexadecimal scale of 00 to FF (0 to 255, base 10).

DATACONTRASTCOLORS=(color-list)

specifies the contrast colors, which are used for lines and markers. You can specify common color names or values of the form CXrrggbb, where the last six characters specify RGB (red, green, blue) values on the hexadecimal scale of 00 to FF (0 to 255, base 10).

DATALINEPATTERNS=(line-pattern-list)

specifies the list of line patterns. Some of the available line patterns are Solid, MediumDash, MediumDashShortDash, LongDash, DashDashDot, LongDashShortDash, DashDotDot, Dash, ShortDashDot, MediumDashDotDot, and ShortDash.

DATASYMBOLS=(marker-symbol-list)

specifies the list of marker symbols. The available markers are ArrowDown, Asterisk, Circle, CircleFilled, Diamond, DiamondFilled, GreaterThan, Hash, HomeDown, HomeDownFilled, Ibeam, LessThan, Plus, Square, SquareFilled, Star, StarFilled, Tack, Tilde, Triangle, TriangleDown, TriangleDownFilled, TriangleFilled, TriangleLeft, TriangleLeftFilled, TriangleRight, TriangleRightFilled, Union, X, Y, and Z.

In the SG procedures, you can override the style attributes and modify how groups are distinguished by using attribute maps:

data myattrmap;
   retain ID 'Attr1' MarkerSymbol 'CircleFilled';
   input Value $ LineColor $ 3-11 MarkerColor $ 13-20;
   datalines;
F pink      cxFFCCEE
M lightblue blue
;

proc sgplot data=sashelp.class dattrmap=myattrmap;
   title 'Separate Fit by Sex';
   reg y=weight x=height / group=sex degree=3 attrid=Attr1;
run;

The results are displayed in Figure 17.

Figure 17: Color Changes with an Attribute Map

Color Changes with an Attribute Map


You can set the following variables and values in the PROC SGPLOT DATTRMAP=SAS-data-set option:

FillColor

color or style attribute

FillStyle

style element

ID

text string that contains the attribute map ID

LineColor

color or style attribute

LinePattern

line pattern or style attribute

LineStyle

style element

MarkerColor

color or style attribute

MarkerStyle

style element

MarkerSymbol

symbol name or style attribute

Value

text string that contains the group

Last updated: December 09, 2022