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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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