BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
myrenO3
Fluorite | Level 6

Hey guys, 

 

I'm new to draw plots by using GTL in sas. Recently I was trying to draw scatter plots but some problems occured when i was trying  a scatterplot within  "layout overlay" block. I used SASHELP.CLASSFIT as my training dataset where x=height and y=weight with group=sex. Also, i wanted to display the plot seperately by using groupdisplay=cluster but I faied. it seemed that the scatterplot was still displayed in a overlay mode. So I'm wondering why the groupdisplay option has no effect? (I run all sas codes in SAS studio 3.8 environment)

here is my code:

 

ods _all_ close;
ods graphics / reset width=900px height=450px;
ods html style=htmlblue path=odsout file="3-scatter.html";
proc template;
  define statgraph myscatter;
    begingraph /; 
      entrytitle "Height and Weight by Sex"; 
      layout overlay / ; 
        scatterplot x=height y=weight / 
           group=sex groupdisplay=cluster name="scatter" markerattrs=(size=12 symbol=starfilled);
      endlayout;	
    endgraph;
  end;
run;

proc sgrender data=sashelp.classfit template=myscatter;
run;

微信截图_20200312223011.png

by the way, I was also wondering how to costomize markers with different  colors (i.e., green and ) between male(sex=M) and female(sex=F) but i don't know how. 

 

 

Thanks in advance for any suggestions!

Myren

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Previously your x variable was 'Height", with "Sex" as the group variable.  Now, your x variable is sex.  Change it back to height to get the different groups within each value of weight.  Make sure to set the axis TYPE=DISCRETE.

View solution in original post

5 REPLIES 5
Jay54
Meteorite | Level 14

GroupDisplay=Cluster is effective when one of the axes is discrete.  You can make your XAXIS discrete to see the effect by setting TYPE=Discrete in the XaxisOpts bundle on the Layout Overlay statement.

 

Use the DATACOLORS option on the BEGINGRAPH statement to set group colors.

 

https://documentation.sas.com/?docsetId=grstatgraph&docsetTarget=n0j696v6yqkb79n12zed3am3omcx.htm&do...

 

https://documentation.sas.com/?docsetId=grstatgraph&docsetTarget=n0j696v6yqkb79n12zed3am3omcx.htm&do...

Jay54
Meteorite | Level 14

For SCATTER marker colors, you need to use the DataContrastColors option.

DataColors is used for "fill" colors.

myrenO3
Fluorite | Level 6

Thanks for your suggestion where I learned a lot.  I succeed changing marker colors by DATACONTRASTCOLORS and displaying scatters  by using a discrete xaxis(See figure 1 below). However,  it seemed that there was still a liitle difference, compared with the example plot in sas reference document (the figure on the right, also see sas document URL here). Perhaps the example here uses a different type of layout? (lattice for example)

figure1.pngfigure2.png

Jay54
Meteorite | Level 14

Previously your x variable was 'Height", with "Sex" as the group variable.  Now, your x variable is sex.  Change it back to height to get the different groups within each value of weight.  Make sure to set the axis TYPE=DISCRETE.

myrenO3
Fluorite | Level 6

Thanks for your reminding. I tried but it seemed that no changes ocurred. here is my code:

 

/*1-Basic scatter plot-*/
ods _all_ close;
ods graphics / reset width=900px height=450px;
ods html style=htmlblue path=odsout file="3-scatter.html";
proc template;
  define statgraph myscatter;
    begingraph / datacontrastcolors=(red green); 
      entrytitle "Simple Scatter plot"; 
      layout overlay / 
      	xaxisopts=(type=discrete); 
        scatterplot x=height y=weight / group=sex groupdisplay=cluster name="scatter" markerattrs=(size=12 symbol=starfilled);
        discretelegend "scatter";
      endlayout;	
    endgraph;
  end;
run;

proc sgrender data=sashelp.classfit template=myscatter;
run;

result:

SGRender.png

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1585 views
  • 4 likes
  • 2 in conversation