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;
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!
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.
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)
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.