- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I wonder if it's possible in GTL to group values by several variables using different attributes for them. For example, I want to plot a scatter plot for sashelp.class where x=Weight and y=Height and where points will be color-coded by Age (11=red, 12=blue etc) and symbol-coded for different Sexes (male=X, female=Circle).
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't think you can group by more than one variable. If you don't need a graph legend, you can do:
data sClass / view=sClass;
set sashelp.class;
if sex="M"
then mHeight = height;
else fHeight = height;
label mHeight="Height" fHeight="Height";
run;
proc sgPlot data=sClass noautolegend;
scatter x=weight y=mHeight / group=age markerAttrs=(symbol="X");
scatter x=weight y=fHeight / group=age markerAttrs=(symbol="Circle");
run;
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I don't think you can group by more than one variable. If you don't need a graph legend, you can do:
data sClass / view=sClass;
set sashelp.class;
if sex="M"
then mHeight = height;
else fHeight = height;
label mHeight="Height" fHeight="Height";
run;
proc sgPlot data=sClass noautolegend;
scatter x=weight y=mHeight / group=age markerAttrs=(symbol="X");
scatter x=weight y=fHeight / group=age markerAttrs=(symbol="Circle");
run;
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, PGStats. Looks like it's the only way to do what I want so far. So I'll need to create legend in some other way (as an additional text element, e.g.). I also found MERGEDLEGEND statement that seems to be a step towards creating multigrouped plots, but it only works for two plots and of certain types (line and marker). Would be great if SAS had the ability to group data by multiple variables or at least to customize legend (so that I could display legend for one of the plots and then change legend's markers from X's or circles to, e.g., squares, emphasizing by this that color matters, not shape).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Good luck. You may also get some level of control by combining your group variables (i.e. sexAge = cats(sex,age); ) and using SG Attribute Maps. SAS(R) 9.3 ODS Graphics: Procedures Guide, Third Edition - PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A simpler, decent alternative is :
proc sgPlot data=sashelp.Class;
scatter x=weight y=height / group=age grouporder=ascending markerchar=sex;
run;
PG
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
And if one of your variables is discrete and you want clustered groups (side by side) you can use GROUPDISPLAY=cluster.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As PG says, combine your groups into a single variable (you can use PROC FREQ for this). Then use data attributes, as shown in this blog post Specify the colors of groups in SAS statistical graphics - The DO Loop