Data visualization with SAS programming

SAS colors for overlay graphs

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

SAS colors for overlay graphs

I use Gplot to overlay 18-20 graphs in the same screen and would like different colors for each of them.

For the symbol statement I use repeat=20 without specifying colors,so the charts are created but the colors are repeated after the 12th graph, seems like the automatically selected colors are only 12, the 13th one is the same as the 1st.

 

What can I do to force SAS to automatically select different colors for each of the 20 graphs? I know I can manually specify 20 colors with 20 symbol statements but I'd rather avoid that.


Accepted Solutions
Solution
‎01-05-2016 07:22 PM
Trusted Advisor
Posts: 1,114

Re: SAS colors for overlay graphs

Indeed, it seems that the limitation to 12 colors is imposed by ODS styles (as @ballardw has pointed out in the other thread). This could be avoided by switching the GSTYLE system option off: options nogstyle;

 

Now, SAS would cycle through the default color list of the device used (excluding WHITE, the background color). The number of colors in this list (at least for the device WIN) has been increased to 38 since SAS 9.2, hence would be sufficient for your 20 graphs. However, the NOGSTYLE system option has side effects (e.g. on fonts) which may or may not be acceptable to you.

 

Alternatively, you could specify a list of (at least) 20 colors in the COLORS= option of the GOPTIONS statement (no need for multiple SYMBOL statements then). As a generic list to start with you could simply copy the color list from the device entry and then edit the list as you like (e.g. delete colors that are hardly visible or too similar to others etc.). I did this in the following code example, based on the default color list of the device WIN (obtained by double-clicking entry WIN in the contents of 'Sashelp.Devices' in the CATALOG window):

 

goptions reset=all;

data test;
array y[20];
do x=1 to 3;
  do i=1 to dim(y);
    y[i]=i;
  end;
  output;
end;
run;

symbol v=dot i=join;

goptions colors=(BLACK   RED    GREEN  BLUE    CYAN
                 MAGENTA GRAY   PINK   ORANGE  BROWN
                 LIME    PERU   GOLD   HOTPINK INDIGO
                 KHAKI   PURPLE SILVER SKYBLUE TOMATO);

proc gplot data=test;
   plot (y:)*x / overlay;
run;
quit;

 

View solution in original post


All Replies
Solution
‎01-05-2016 07:22 PM
Trusted Advisor
Posts: 1,114

Re: SAS colors for overlay graphs

Indeed, it seems that the limitation to 12 colors is imposed by ODS styles (as @ballardw has pointed out in the other thread). This could be avoided by switching the GSTYLE system option off: options nogstyle;

 

Now, SAS would cycle through the default color list of the device used (excluding WHITE, the background color). The number of colors in this list (at least for the device WIN) has been increased to 38 since SAS 9.2, hence would be sufficient for your 20 graphs. However, the NOGSTYLE system option has side effects (e.g. on fonts) which may or may not be acceptable to you.

 

Alternatively, you could specify a list of (at least) 20 colors in the COLORS= option of the GOPTIONS statement (no need for multiple SYMBOL statements then). As a generic list to start with you could simply copy the color list from the device entry and then edit the list as you like (e.g. delete colors that are hardly visible or too similar to others etc.). I did this in the following code example, based on the default color list of the device WIN (obtained by double-clicking entry WIN in the contents of 'Sashelp.Devices' in the CATALOG window):

 

goptions reset=all;

data test;
array y[20];
do x=1 to 3;
  do i=1 to dim(y);
    y[i]=i;
  end;
  output;
end;
run;

symbol v=dot i=join;

goptions colors=(BLACK   RED    GREEN  BLUE    CYAN
                 MAGENTA GRAY   PINK   ORANGE  BROWN
                 LIME    PERU   GOLD   HOTPINK INDIGO
                 KHAKI   PURPLE SILVER SKYBLUE TOMATO);

proc gplot data=test;
   plot (y:)*x / overlay;
run;
quit;

 

SAS Super FREQ
Posts: 1,044

Re: SAS colors for overlay graphs

The ODS Styles do not have an inherent limitation of 12 group values.  Most SAS shipped styles do have only up to 12 groups defined, but the style definition itself can have as many as you want.  Actually, many experts in the UI area will attest that having discernable colors greater than eight is a challange anyway, and many new SAS styles have only eight.

 

 

You can derive your own style from one of the popular SAS styles and increase the number of group levels by adding more GRAPHDATAxx elements from 13 to 99.  You can also use the %MODSTYLE macro for this.  see Doc for %MODSTYLE.

 

 Statgraph procedures (GTL and SG) cycle the usage of colors, symbols and patterns to give many more distinct group levels.  84 for markers and 132 for lines.

Contributor
Posts: 71

Re: SAS colors for overlay graphs

Thanks Sanjay.
Contributor
Posts: 71

Re: SAS colors for overlay graphs

Thanks!
Post a Question
Discussion Stats
  • 4 replies
  • 380 views
  • 5 likes
  • 3 in conversation